E
ExcelMonkey
I keep trying to post this in this forum but the moderators keeping moving it
other formums PLEASE STOP DOING THIS.
I amtrying to loop through some VB Project components in Excel via .NET
In VBA I would do the following:
Dim VBComp As VBIDE.VBComponent
For Each VBComp In ThisWorkbook.VBProject.VBComponents
Next
In .Net I am doing the following:
Dim VBComp As Microsoft.Vbe.Interop.Component
For Each VBComp In xlBook.VBProject.VBComponents
Dosomething(VBComp)
Next
Sub DoSomething(ByVal X As Microsoft.Vbe.Interop.Component)
'Do something
End Sub
If fails on the line: DoSomething (VBComp)
and says:
System.InvalidCastException was unhandled
Message="Unable to cast COM object of type 'System.__ComObject' to
interface type 'Microsoft.Vbe.Interop.Component'. This operation failed
because the QueryInterface call on the COM component for the interface with
IID '{0002E163-0000-0000-C000-000000000046}' failed due to the following
error: No such interface supported (Exception from HRESULT: 0x80004002
(E_NOINTERFACE))."
I thought I may have found a response regarding the use of an explicit cast
at this link:
http://social.msdn.microsoft.com/Fo...1b-3eea65796dd2
However I cannot get this to work as VBIDE.VBProject does not work in .Net.
What am I doing wrong?
Thanks
EM
other formums PLEASE STOP DOING THIS.
I amtrying to loop through some VB Project components in Excel via .NET
In VBA I would do the following:
Dim VBComp As VBIDE.VBComponent
For Each VBComp In ThisWorkbook.VBProject.VBComponents
Next
In .Net I am doing the following:
Dim VBComp As Microsoft.Vbe.Interop.Component
For Each VBComp In xlBook.VBProject.VBComponents
Dosomething(VBComp)
Next
Sub DoSomething(ByVal X As Microsoft.Vbe.Interop.Component)
'Do something
End Sub
If fails on the line: DoSomething (VBComp)
and says:
System.InvalidCastException was unhandled
Message="Unable to cast COM object of type 'System.__ComObject' to
interface type 'Microsoft.Vbe.Interop.Component'. This operation failed
because the QueryInterface call on the COM component for the interface with
IID '{0002E163-0000-0000-C000-000000000046}' failed due to the following
error: No such interface supported (Exception from HRESULT: 0x80004002
(E_NOINTERFACE))."
I thought I may have found a response regarding the use of an explicit cast
at this link:
http://social.msdn.microsoft.com/Fo...1b-3eea65796dd2
However I cannot get this to work as VBIDE.VBProject does not work in .Net.
What am I doing wrong?
Thanks
EM