Quick answer: ThisWorkbook.[_CodeName] = "newName"
Detailed answer
When I add references to the Microsoft Visual Basic For Applications Extensibility 5.3
and run your line
ThisWorkbook.VBProject.VBComponents("ThisWorkbook").Name = "wb"
The ThisWorkbook
Name property isn't actually being modified
Saving and re-opening the file causes a duplication of the ThisWorkbook
object
Which pretty much means now I have two Workbook
objects within one workbook and both are named ThisWorkbook
The workaround is to rename the ThisWorkbook
to wb
using the Properties window or
ThisWorkbook.[_CodeName] = "newName"
because ThisWorkbook.CodeName
is read-only.