Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB Script

Status
Not open for further replies.

billyd380

IS-IT--Management
Nov 23, 2004
20
0
0
US
I have this script that does half of what I want but I can't figure out how to get it to do the rest. If you copy it into a standard model it will pretty much explain what it does. What I need it to do is if you save save the file with and new name so you can keep the templet the same and colse the new file, it will change the number in H1 and I don't want it to. I want all old files to keep the number it has and only the templet to change. I have tried a few different IF...Then...Else statements but I can't get any of them to work. If someone could shoot me to the right direction that would be great. Here is the code:

Sub Auto_open()

On Error GoTo ErrorHandler

One:

Open "c:\Counter.txt" For Input As #1
Input #1, x
Close #1
x = x + 1


Two:
Sheets(1).Range("h1").Value = x
Open "c:\Counter.txt" For Output As #1
Write #1, x
Close #1

Exit Sub
ErrorHandler:
Select Case Err.Number
Case 53 'If Counter file does not exist...
x = InputBox("Enter Number to Begin Counting With", "Create 'Counter.txt' File")
Resume Two
Case Else
Resume Next




End Select




End Sub


Thanks,

Bill
 
Bill,
Try adding the following just below your error handling statement:
Code:
If Sheets(1).Range("h1").Value <> "" Then
   Exit Sub
End If

Hope this helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top