I copied from stackoverflow, and I get "Run-time Error 1004" Expecting object to be local on line ActiveWorkbook.VBProject.Name = "VBAProject" Why?

Viewed 32

I guess what my question is, 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

At the end of the day 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
1 Answers

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:

enter image description here

Related