ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Can't pass VBComponent to Sub Procedure in VB.Net (https://www.excelbanter.com/excel-programming/435222-cant-pass-vbcomponent-sub-procedure-vbulletin-net.html)

ExcelMonkey

Can't pass VBComponent to Sub Procedure in VB.Net
 
I posted this a few days back and for some reason cannot find this in the
Microsift Office Newsgroups. Yet when I google it shows up he

http://www.pcreview.co.uk/forums/thread-3908301.php

Anways here it is again:

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))."

There was a response which suggested going to the following link as it
highlights that seems that I may need the explicit cast:

http://social.msdn.microsoft.com/For...b-3eea65796dd2

But I cannot get this to work either. It uses the following sytax:
Friend Sub copyComponents(ByVal src As
Microsoft.Office.Interop.Excel.Workbook)

Dim srcVBP As VBIDE.VBProject = src.VBProject
For Each vbaComp As VBIDE.VBComponent In srcVBP.VBComponents

Next

I cannot type in VBIDE.VBProject as a declaration. Its does not work.

What am I doing wrong?

Thanks

EM



All times are GMT +1. The time now is 08:38 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com