Reputation: 11
What is VBAProject? Is VBAProject my Program.xlsm file because if I replace with that I get the same error.
I tried adding to find the name:
Dim myString As String
myString = ThisWorkbook.VBProject.Name
But got a similar error.
I am trying to change the CodeName of my Template Worksheet WS0000 to WS0002, WS0003... WS0nnn within my VBA code.
Sub ChangeCodeName()
Dim wbk As Object, Sheet As Object
ActiveWorkbook.VBProject.Name = "VBAProject"
Set wbk = ActiveWorkbook.VBProject.VBComponents(ActiveWorkbook.CodeName)
wbk.Name = "WS0000"
Set Sheet = ActiveWorkbook.VBProject.VBComponents(ActiveWorkbook.Sheets(1).CodeName)
Sheet.Name = "WS0002"
End Sub
Upvotes: 0
Views: 1961
Reputation: 6829
Leaving image to turn on the trust access to the VBA project, under Trust Center -> Macro Settings -> Developer Macro Settings, as outlined in my comment to the post:
Upvotes: 0