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.
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.
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.
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.