Porting VB6 addin code to new Excel workbook

M

MAB

I have an addin that creates a new Excel Workbook. I want to have the addin,
add code to the new workbook. Specifically I want to add a right click menu
and the code module for the menu. The following website gives great insite
manipulating code on the VBA side which I'm sure I'll need here but what I
don't have is the VB6 side (if there is one).

http://www.cpearson.com/excel/vbe.htm#CopyModule

VBA can create new modules/class/etc, populate item, export them, import
them. Can VB6 do any of this? If so, what/how?

I'd rather (if possible) take modules/classses/etc internal to the addin and
copy (directly or indirectly [export to file]) them in to the new workbook as
opposed to supplying extra files to VBA import.
 
X

XL-Dennis

Hi,

COM Add-ins differ from native Excel add-ins in that they are compiled and
therefore it's not possible to add an 'internal' module to Excel's workbooks.

You got two options to consider:
Write a procedure/functions that create and add a module including the
wanted procedures etc.
Import a BAS module which reside outside the DLL but in same directory and
then use the following code:

Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook

Set xlApp = New Excel.Application

Set xlBook = xlApp.Workbooks.Add

xlBook.VBProject.VBComponents.Import App.Path & "\Test.bas"

With xlApp
.Visible = True
.UserControl = True
End With

Set xlBook = Nothing
Set xlApp = Nothing


The info from Chip Pearson's page can be used in VB as well.

---------------
With kind regards,
Dennis
Weekly Blog .NET & Excel: http://xldennis.wordpress.com/
My English site: http://www.excelkb.com/default.aspx
My Swedish site: http://www.xldennis.com/
 

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