![]() |
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 |
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 |
All times are GMT +1. The time now is 04:19 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com