can we copy the code from the addin to excel workbook

V

vicky

Is there any code thru which we can copy the code from addin to a
excel workbook .. in the addin i have a code written in thisworkbook
and have 1 module ..
 
J

joel

The process requires you to save the macro as a BAS file then read th
BAS file into the 2nd workbook. Chip Pearson has good instructions a
his website

'Programming In The VBA Editor
(http://www.cpearson.com/excel/vbe.aspx)

Read the two bullets at the top of the webpage carefully especially

•Next, you need to enable programmatic access to the VBA Project. I
Excel 2003 and earlier, go the Tools menu (in Excel, not in the VB
editor), choose Macros and then the Security item. In that dialog, clic
on the Trusted Publishers tab and check the Trust access to the Visua
Basic Project setting
 
C

Chip Pearson

Try something like

Dim TempFile As String
Dim ModuleName As String
Dim FromWB As Workbook
Dim DestWB As Workbook

Set FromWB = Workbooks("YourAddInFile.xla")
Set DestWB = ThisWorkbook
ModuleName = "modConstants"
TempFile = Environ("Temp") & "\" & ModuleName & ".bas"
On Error Resume Next
Kill TempFile
On Error GoTo 0
FromWB.VBProject.VBComponents(ModuleName).Export _
Filename:=TempFile
DestWB.VBProject.VBComponents.Import _
Filename:=TempFile
On Error Resume Next
Kill TempFile
On Error GoTo 0

For modules, use ".bas" as shown in the TempFile = line of code. For
userforms, use ".frm", and for class modules, sheet modules, and
ThisWorkbook, use ".cls". This assumes that the add-in's VBProject is
not locked and that the "Allow Access To The VB Project" is enabled.

See www.cpearson.com/Excel/VBE.aspx for much more detail.

Cordially,
Chip Pearson
Microsoft MVP 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com
[email on web site]
 

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