Link to home
Create AccountLog in
Avatar of swimehdi
swimehdiFlag for United States of America

asked on

Macro independence

I created a button and assigned  a macro to it- see attachment.

I am wondering if it is possible to make this button independent. In other words, the language generated from the Macro is embedded in the button. The benefit of this is:

The user can copy and paste the button from one workbook to a new workbook  without having the macro linked to the original workbook.  

Another possible way to accomplish this is when the user copies and pastes the button from one workbook to a new workbook it generates the macro language in the new workbook and discontinues the linkage to the old workbook.

I hope I will find an answer to this.

Thank you for your help expert.
Avatar of Eirman
Flag of Ireland image

I don't think that this is possible

If you put the relevant code in a module you can copy the button from one sheet to another and just use the existing module.


Keep the code in a sheet and copy the code and the button between sheets and/or workbooks
Avatar of swimehdi


What about the option to have the macro executable to all open workbooks?
Avatar of byundt
Flag of United States of America image

Link to home
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
The direct answer to your original question is that it is impossible. The best we can do is offer an explanation for why, and one or more workarounds.

The macro code lives in either a regular module sheet (for a Forms command button such as you are using) or in the code pane for the worksheet containing an ActiveX button. Either way, it doesn't copy with the button, unfortunately.

Note that if you want to give your workbook to other users, having a command button linked to your Personal.xlsm as previously suggested is not a good solution. You are better off in that case copying the code into each new workbook that you want to install the button in.

Thank you Brad !