Exporting & Importing Macro with VBA

s_woodbury

New Member
Joined
Feb 26, 2014
Messages
27
Hey all, I'm trying to move a module to a new Workbook and assign it to a shape

I can Export/Import it but when I assign it I'm assigning the macro from the Original, not the New Workbook.

The New Workbook's name will change each time it's run. I don't know how to code a variable into the OnAction Line.

Here's the code I'm using any suggestions is appreciated. I'm stuck!

'Copy Module from ThisWorkBook to the path and folder of ThisWorkBook
MSRMaster.VBProject.VBComponents("Active_Customer_Filter").Export strTempFile1

'Copy the Module we saved earlier from ThisWorkBook to the New Workbook
Application.VBE.ActiveVBProject.VBComponents.Import (strTempFile1)

'Assign Macro to Shape already created
ActiveSheet.Shapes.Range(Array("Button 1")).Select
Selection.OnAction = "Active_Customer_Filter.bas"
 
Last edited:

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Do you know you can put Macros into your Personal Workbook
And then run the Macro from any Workbook New or Old?
 
Upvote 0
This solved my problem:

Selection.OnAction = _
"'" & ActiveWorkbook.Name & "'" & "!Active_Customer_Filter.Active_Customer_Filter"
 
Upvote 0
How are you creating the new workbook?
 
Upvote 0
Why not create a workbook with all the required buttons/code etc. in it?

Then when you create the new workbook use that as a template and copy the data from the user selected file to it.
 
Upvote 0

Forum statistics

Threads
1,223,632
Messages
6,173,472
Members
452,516
Latest member
archcalx

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top