M
Marcin
Hi,
I have serious problem with accessing VBProject of another Excel workbook.
I need to play with VBComponents and check CodeNames of all sheets.
Always when code refers to VBProject of another workbook error 1004 mentioned in subject of this post is generated.
Notes:
- “Trust access to the VBA project object model” is set on in Trust Center / Macro setting
- reference to “Microsoft Visual Basic for Application Extensibility 5.3” is added
- opened file is located in network drive
Below there is part of code in VBA.
Do you know what can be the reason of that problem?
Private Sub Test()
Dim MyFiles As Variant
Dim Fnum As Byte
Dim mybook As Workbook
Dim mybookProject As VBIDE.VBProject
Dim VBC As VBIDE.VBComponent
MyFiles = Application.GetOpenFilename(filefilter:="Excel Files (*.xls),*.xls", MultiSelect:=True)
If IsArray(MyFiles) Then
For Fnum = LBound(MyFiles) To UBound(MyFiles)
Set mybook = Application.Workbooks.Open(MyFiles(Fnum), , True)
‘***** next line an error occurs ******
Set mybookProject = mybook.VBProject
For Each VBC In mybookProject.VBComponents
If VBC.Type = 100 Then
...
...
Kind regards,
Marcin
I have serious problem with accessing VBProject of another Excel workbook.
I need to play with VBComponents and check CodeNames of all sheets.
Always when code refers to VBProject of another workbook error 1004 mentioned in subject of this post is generated.
Notes:
- “Trust access to the VBA project object model” is set on in Trust Center / Macro setting
- reference to “Microsoft Visual Basic for Application Extensibility 5.3” is added
- opened file is located in network drive
Below there is part of code in VBA.
Do you know what can be the reason of that problem?
Private Sub Test()
Dim MyFiles As Variant
Dim Fnum As Byte
Dim mybook As Workbook
Dim mybookProject As VBIDE.VBProject
Dim VBC As VBIDE.VBComponent
MyFiles = Application.GetOpenFilename(filefilter:="Excel Files (*.xls),*.xls", MultiSelect:=True)
If IsArray(MyFiles) Then
For Fnum = LBound(MyFiles) To UBound(MyFiles)
Set mybook = Application.Workbooks.Open(MyFiles(Fnum), , True)
‘***** next line an error occurs ******
Set mybookProject = mybook.VBProject
For Each VBC In mybookProject.VBComponents
If VBC.Type = 100 Then
...
...
Kind regards,
Marcin