Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
find workbooks with macros Mike Molyneaux Excel Programming 0 June 4th 04 09:55 PM
Passing a variable between workbooks Rich Cooper Excel Programming 1 May 19th 04 07:27 PM
Passing Execution Control Between Workbooks RSnyder[_2_] Excel Programming 0 May 7th 04 02:01 PM
passing value with button to macros pabs[_13_] Excel Programming 3 January 6th 04 05:10 PM
Using VBA macros in all workbooks Ian Griffiths Excel Programming 6 September 1st 03 12:15 AM


All times are GMT +1. The time now is 09:43 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"