Execute macro on document open?

I have an Excel worksheet that uses external data sources, which means they're disabled on open and I have to dismiss two annoying banners. I can (relatively) easily automate this stupidity away with KM, but what I'd really like to do is have the macro run on document open.

Note that the macro should not run when the document becomes active (i.e. it was already open and I just switched to it), but only on initial open.

I can, of course, get around all of this by having the macro open the file as the first step, but I often open the file by double-clicking in Finder...I'd have to retrain myself to run the macro instead.

Is this possible?


yup, you can do. For initial open
Use 'on launch'

and also use a 'Pause Until'

might also need to pause some seconds until it finally loads.

Thanks, but isn't that just for the app itself? I need the macro to run when a specific document opens in the app (Excel is almost always running).


yeah, my bad.

re-read the post. I think you need to go a different route:
Try with the condition: 'title'

I thought about that one, but then the macro would launch every time the window came to the foreground. I need this to run when it first opens, but after that, it'd fail (because the banners aren't there).

I guess if it failed silently, that wouldn't be too bad.


how frequently do you need it to run?
does it need to run once a day?

It's a worksheet with some stock prices in it; I open and close it multiple times a day. There's nothing that really runs, but it won't update until you manually remove a couple warnings. I think I'll just write the macro and invoke it manually; it'll still save a bunch of mouse move-and-click action.


1 Like

Then add a test for the "banners". They probably have some buttons you could check for using the Button condition, or maybe they present a different window title.

I did eventually get it working, using a "find image" check. But it then always running, silently launching and stopping if the image isn't found. In the end, I went back to a hot key that I press after opening the file—it gets rid of the banners and does a refresh on the external data source. Works well enough—one hot key vs. a fair bit of mouse moving.

Thanks for the help!


Did you try my suggestion?


  • Macro Group: Excel only
  • Macro Trigger: Window change


  1. If banner buttons are enabled;
    • Then proceed to click and close the popup banner
    • Else Cancel macro.

Easy enough, and is NOT CPU intensive.