Worksheet naming using visual basic
What I have is a work schedule based on a calendar setup. I currently use a
macro to automatically save the "schedule" worksheet by copying the worksheet
to a new sheet which renames it using the date from cell A2, i.e. "26 Oct -
15 Nov 2006".
The code looks like this:
Sheets("SCHEDULE").Copy AFTER:=Worksheets(Worksheets.Count)
Sheets("SCHEDULE (2)").Select
Cells.Select
Selection.Copy
Selection.PasteSpecial paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Range("a1").Select
Sheets("SCHEDULE (2)").Name = Sheets("SCHEDULE (2)").Range("$a$2")
Sheets("INFO").Select
Calculate
Sheets("SCHEDULE").Select
Range("A1").Select
The problem I have is that when I make a mistake and/or correction and try
to save it again I get the old run time error 1004 saying that you can't
rename a sheet when I have that same existing name from the previous save.
When I stop the debugger it still copies it to "schedule (2)".
Here's what I want. I want it to either overwrite the same named file with
the new one or automatically name it with the date and the (2) symbol and so
on. I don't want the debugger to be tripped by an error.
I appreciate any help you can give me...
|