How to automatically run a macro upon opening a workbook (using a clickable prompt)?

Sam Hamels

New Member
Joined
Mar 20, 2018
Messages
49
Hi All,

I would like a macro to start running automatically as soon as I open the Excel file.
However, a prompt would ideally appear first, which asks if the user wants to cancel the automatic start of the macro.
The user has the option to click on the prompt (or hit a specific key or something), to cancel the automatic start of the macro.
If the user does not interact with the prompt (lets say he is given a few seconds to do so), the prompt simply disappears and the macro automatically starts running.

I've tried messing around with some things I found by Googling but can't get anything to work.


Thanks in advance for any tips or help!

Cheers,
Sam
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Hi Eric,


Thanks for the tips.
After looking into the times prompt, I figured out that a much simpler method was OK for my needs, namely a simple combination of the following two things:

1: setting up the following Workbook_Open event:

Code:
Private Sub Workbook_Open()


Application.OnTime Now + TimeValue("00:00:5"), "Macro1"


End Sub


2: Create the following macro in a separate module:

Code:
Sub Macro1()


If Range("A1").Value = 1 Then MsgBox "A1 = 1"


End Sub


I now have 5 seconds to change the value in cell A1 to something else than 1, to avoid "the macro" from running automatically.
By "the macro", I mean the MsgBox in my Example, which will be a much more complicated macro in the actual application.


Cheers,
Sam
 
Upvote 0

Forum statistics

Threads
1,224,822
Messages
6,181,165
Members
453,021
Latest member
Justyna P

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