Why does Macro button automatically open workbook?

debbos

New Member
Joined
Feb 26, 2021
Messages
2
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.
 

Some videos you may like

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.

alansidman

Well-known Member
Joined
Feb 26, 2007
Messages
6,149
Office Version
  1. 365
Platform
  1. Windows
I suspect without actually seeing your code, that it contains instruction to open that particular file.
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,265
Office Version
  1. 365
Platform
  1. Windows
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.
 
Solution

debbos

New Member
Joined
Feb 26, 2021
Messages
2
Office Version
  1. 365
Platform
  1. Windows
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,127,308
Messages
5,623,890
Members
416,000
Latest member
Sovereign maphoso

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