Using Excel 2010.
I need to add code to a remote Excel file where ThisWorkbook module has been renamed, let's say to "DashboardWorkbook". I don't know however the new name, can be anything but I need to identify this module programmatically in order to add more code to Sub Workbook_Open().
I am opening this remote file, then I go through all it's components:
Private Sub AddProcedureToWorkbook(wb As Workbook)
Dim VBProj As VBIDE.VBProject
Dim oComp As VBIDE.VBComponent
Dim oCodeMod As VBIDE.CodeModule
Set VBProj = wb.VBProject
For Each oComp In VBProj.VBComponents
If *[check here if oComp was formerly ThisWorkbook but now renamed]* Then
Set oCodeMod = oComp.CodeModule
'add new code here
...etc, etc
End If
Next
End Sub
In Excel interface, ThisWorkbook has a different icon so it seems to be a different module type but I could not figure out what specific property to read in order to identify it?
To complicate things even more, sometimes Sub Workbook_Open() doesn't exist, therefore I need to add it at the right place...
Thank you,
M.R.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…