Help With Macro Buttons

jtfannin

New Member
Joined
Aug 22, 2006
Messages
4
I can assign a macro to a button with no problem but it will open that file if that button is used in a different file. How do I get the button to work for any file and not open the file it was assigned in.

Thanks
 

Some videos you may like

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).

jtfannin

New Member
Joined
Aug 22, 2006
Messages
4
There is no code to post. It is just a general question involving the assign macro command button in Excel. If I assign the button with macro1 it will open the original buttton assign. If I just shortcut key the macro (ex. Ctrl+r) it works without opening original file.
 

Datsmart

Well-known Member
Joined
Jun 19, 2003
Messages
7,985
If two different things are happening between marco1 and the macro with Ctrl+r assigned to it, then there must be two different macros.
I agree with shajurasow, please post the code. And check for two different macros.
 

Derek

Well-known Member
Joined
Feb 16, 2002
Messages
1,592
Hi there

When you copy a macro button (or a sheet with a button) to a different workbook then the macro assigned to it is the macro in the original file. So when you click the button it will open the original file to find the original macro code.

You can see this by right click on the button, left click Assign Macro and note that the macro name in the title box refers to another file.

What you need to do is copy the module from the original file into your new file. Have both files open, then in the VB Editor find both projects in the Project window and simply drag the module from the original file to the new file (this produces a copy). Now you need to reassign the macro in your new file. Right click the button, left click Assign Macro, set the lower dropdown box to "This WorkbooK". The macro names in the main window will now drop any filename prefix and just leave the macro name. Select the one you want.

EDIT: The above is based on a button from the Forms toolbar. I rarely see a need to use a command button, but presumably the same applies.

Regards
Derek
 

Watch MrExcel Video

Forum statistics

Threads
1,122,486
Messages
5,596,448
Members
414,066
Latest member
rjoiner3

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
Top