Can't pass VBComponent to Sub Procedure in VB.Net

E

ExcelMonkey

I am getting an error in VB.Net when trying to do the following:

Dim VBComp As Microsoft.Vbe.Interop.VBComponent
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))."

Why is this?

Thanks

EM
 
S

Stefan Hoffmann

hi,
I am getting an error in VB.Net when trying to do the following:
I would test something like this (it's a mix between VBA and C#):
Dim VBComp As Microsoft.Vbe.Interop.VBComponent Dim test As Object
For Each VBComp In xlBook.VBProject.VBComponents
Set test = VBComp As Microsoft.Vbe.Interop.VBComponent
If test Is Nothing Then MsgBox("huh?")
DoSomething (VBComp)
Next
Sub DoSomething(ByVal X As Microsoft.Vbe.Interop.Component)
hmm, in C# I would use a call by reference not by value here, but this
should not make a difference.
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))."
Why is this?
Is Excel installed correctly on your target machine? Try running a
repair installation.

btw, you're in the wrong newsgroup, this one is about coding for MS
Access. You should use one of these:

- microsoft.public.excel.interopoledde (ok, sounds outdated)
- microsoft.public.framework.interop
- microsoft.public.dotnet.languages.vb

mfG
--> stefan <--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top