Get the name of a newly copied worksheet
You have to make the hidden worksheet "Invoice Template" visible first,
before you can copy it (at least in Excel 2000 SP-3). You might also have to
copy the worksheet, then Set newSheet in a separate statement following the
statement that copies the worksheet.
Set wsTemplate = Worksheets("Invoice Template")
With wsTemplate
.Visible = xlSheetVisible 'Make Invoice Template visible.
.Copy Befo=Worksheets(1)
'newSheet is now Sheet1; previous Sheet1 should now be Sheet2.
Set newSheet = Worksheets(1)
.Visible = xlSheetHidden
End With
With newSheet
'Remaining code here.
End With
Also, the .Select statement after the "With newSheet" should probably be
..Activate
Single step through your code and verify these object variables in the Local
window as you go.
(You "Select" ranges, but you "Activate" worksheets and the activecell.)
--
Regards,
Bill
"Richard" wrote in message
news:32akc.42981$0u6.7133357@attbi_s03...
I am trying to copy a worksheet then make it active as shown in the code
below, but the Set command
does not work. Is this the correct way to grab the identity of a newly
copied worksheet? The
worksheet "Invoice Template" is hidden, so that's why the ".Visible"
statement.
Set newSheet = Worksheets("Invoice Template").Copy befo=Worksheets(1)
With newSheet
.select
.Visible = xlSheetVisible
result = InputBox("Enter a name for your new invoice", "Name your
invoice")
If result < "" Then
.Name = result
Else
.Name = "Invoice - " & Format(Date, "mmm_d_yyyy")
End If
end with
Thank you, Richard
|