PC Review


Reply
Thread Tools Rate Thread

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

 
 
ExcelMonkey
Guest
Posts: n/a
 
      21st Oct 2009
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 here:

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

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't pass VBComponent to Sub Procedure in VB.Net ExcelMonkey Microsoft Access VBA Modules 2 19th Oct 2009 09:40 AM
problem how to pass value from one procedure to another Dan Microsoft VB .NET 9 22nd May 2008 02:12 PM
Pass Parameter to stored procedure in pass thru query SAC Microsoft Access Queries 7 11th Jul 2007 12:49 PM
Pass Procedure Name? Mike Hoff Microsoft VB .NET 4 8th Jan 2005 03:42 AM
By pass Log on procedure?? JER Windows XP General 6 27th Oct 2004 11:22 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:58 AM.