Why does Macro button automatically open workbook?

debbos

New Member
Joined
Feb 26, 2021
Messages
4
Office Version
  1. 365
Platform
  1. Windows
This is not a problem, just what seems like weird Excel behaviour that I’d like to understand.

I’m using Excel 365 on a Windows 10 desktop PC. I have a workbook with modules designed to operate on that workbook, call it A. I added a macro button to the Quick Access Toolbar assigned to the top level sub in A. So the button is there on the toolbar of every other workbook too.

Here’s the weird part: if I press the macro button on another workbook, when A isn’t even open, Excel actually opens it and runs the macro. It doesn’t cause a problem - at least it hasn’t so far - but I didn’t think this was supposed to happen automatically i.e. a macro button opening a workbook without any code to make that happen.

Can someone explain it? Apologies if it’s a stupid question with an obvious answer but I’ve done a lot of searches without any joy.
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
I suspect without actually seeing your code, that it contains instruction to open that particular file.
 
Upvote 0
The macro button will be trying to access the code in workbook A and the only way it will do that is by opening workbook A.

You'll see similar behaviour if you create a button on a worksheet and assign a macro to it then copy that button to a worksheet in another workbook.

If you click the copied button the original workbook, if it's not already open, will be opened.
 
Upvote 0
Solution
The macro button will be trying to access the code in workbook A and the only way it will do that is by opening workbook A.

You'll see similar behaviour if you create a button on a worksheet and assign a macro to it then copy that button to a worksheet in another workbook.

If you click the copied button the original workbook, if it's not already open, will be opened.
Thank you, that makes sense. I thought that must be happening but just couldn’t find it documented anywhere or any comment about it. I would have expected Excel to return an error if the workbook wasn’t open rather than helpfully opening it.
 
Upvote 0

Forum statistics

Threads
1,214,584
Messages
6,120,385
Members
448,956
Latest member
JPav

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