Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Passing Macros Between Workbooks
KTR,
Working Hard, or Hardly Working? ;-) The easiest way is to have the macro in its own module, then use code like this (which requires a reference to MS VBA Extensibility): change the module name to match your actual name. The 'myFile' value doesn't need to be changed, since the file is exported to the default folder, then deleted at the end of the code. Sub AddModuleToActiveWorkbook() Dim myFile As String myFile = "MyVBAFile.bas" ThisWorkbook.VBProject.VBComponents("InsertYourAct ualModuleNameHere").Export (myFile) ActiveWorkbook.VBProject.VBComponents.Import (myFile) Kill myFile End Sub HTH, Bernie MS Excel MVP "KTR Working Hard" <KTR Working wrote in message ... The VBA Program I'm working with is meant to open another excel document, make changes to it, save it, and close it. One of the changes I need to make is to add a drop down/combo box that has certain abilities. I would like to assign this combo box a macro to run if changed. How do I pass a macro to this opened excel document through code. I know in VBA I can just click and drag it. But that does me no help. Thanks KTR |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Passing Macros Between Workbooks
KTR,
Bad line wrapping on these lines: ThisWorkbook.VBProject.VBComponents("InsertYourAct ualModuleNameHere").Export (myFile) The (myFile) should be on the same line as the .Export code, with a space between. HTH, Bernie MS Excel MVP "Bernie Deitrick" <deitbe @ consumer dot org wrote in message ... KTR, Working Hard, or Hardly Working? ;-) The easiest way is to have the macro in its own module, then use code like this (which requires a reference to MS VBA Extensibility): change the module name to match your actual name. The 'myFile' value doesn't need to be changed, since the file is exported to the default folder, then deleted at the end of the code. Sub AddModuleToActiveWorkbook() Dim myFile As String myFile = "MyVBAFile.bas" ThisWorkbook.VBProject.VBComponents("InsertYourAct ualModuleNameHere").Export (myFile) ActiveWorkbook.VBProject.VBComponents.Import (myFile) Kill myFile End Sub HTH, Bernie MS Excel MVP "KTR Working Hard" <KTR Working wrote in message ... The VBA Program I'm working with is meant to open another excel document, make changes to it, save it, and close it. One of the changes I need to make is to add a drop down/combo box that has certain abilities. I would like to assign this combo box a macro to run if changed. How do I pass a macro to this opened excel document through code. I know in VBA I can just click and drag it. But that does me no help. Thanks KTR |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
find workbooks with macros | Excel Programming | |||
Passing a variable between workbooks | Excel Programming | |||
Passing Execution Control Between Workbooks | Excel Programming | |||
passing value with button to macros | Excel Programming | |||
Using VBA macros in all workbooks | Excel Programming |