Run Macro on Open

karldugan

New Member
Joined
May 10, 2016
Messages
42
Hi all,

I've got the below macro, if I run it once, then the timer starts and it will keep saving every 10mins but unless I first run the macro, the timer doesn't seem to start. How do I set it so the macro either runs straight away when opened (and so kick starts the timer) or start the timer as soon as the file is opened?

Thanks for ny help.
Karl.

Sub Save()

Dim Duration, Start

Duration = 600
Start = Timer
Do While Timer < Start + Duration
DoEvents
Loop

ActiveWorkbook.Save
MsgBox ("File Saved")

Save
End Sub
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
If you use the Workbook_Open event procedure in VBA, your code will run automatically whenever you open the workbook (as long as VBA/Macros are enabled).
You would simply put the body of your code in this procedure.

Note: NEVER used reserved words like "Save" as the name of your procedures, functions, or variables ("reserved words" are words already used by Excel as the names of functions, properties, methods, or objects). It can cause errors and unexpected results (i.e. when you try to reference "Save", Excel could get confused, as it cannot be sure if you are trying to "Save" the file or call the "Save" procedure).

If you aren't sure if a word is reserved or not, I usually just preface it with "My", to be sure, i.e. "MySave".
 
Upvote 0

Forum statistics

Threads
1,214,922
Messages
6,122,281
Members
449,075
Latest member
staticfluids

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