For some reason the below code only works when run in the vbe, when run in the event handling code, or by macro list the codename remains sheet1.
Please can someone investigate ?
Sub changesheetcodename()
Dim ws,tsst as worksheet
For Each Ws In ActiveWorkbook.Worksheets
If Ws.Name <> "Instructions" then ws.delete
Next Ws
Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = "Sheet1"
set tsst = Sheets("Sheet1")
With tsst
.Parent.VBProject.VBComponents(.CodeName) _
.Properties("_CodeName") = "test"
End With
End Sub
Dim tsst As ...
tsst
which is important. As it stands, it should error because as far as I can see,tsst
is set toNothing
.ws
is currently being declared as aVariant
. You cannot declare multiple variables in this format with VBA. You would rather need toDim ws as Worksheet, tsst as Worksheet
for both to be declared as worksheets.