Run Macro on Monday when workbook opened

sean1541

New Member
Joined
Feb 14, 2023
Messages
31
Office Version
  1. 2016
Platform
  1. MacOS
Hi I want to run a macro when a workbook is opened on a Monday but only run it on the first occasion that it is opened on Monday any help on this would be great
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Have the macro capture and store the data in an unused cell somewhere on your worksheets (and immediately save the file).
Then you can have the first step of the macro to check that date. If it is today, then exit the sub and do not go any further.
Otherwise, check to see if it is a Monday or proceed with the rest of your code.

You would use a "Workbook_Open" event procedure, which runs automatically whenever a file is opened.
That code would be structured like this, and MUST be placed in the "ThisWorkbook" module is in order to run automatically upon opening of the file:
VBA Code:
Private Sub Workbook_Open()

'   Check to see if data in cell Z1 on Sheet1 is today, and if so, exit
    If Sheets("Sheet1").Range("Z1") = Date Then Exit Sub
   
'   Exit if not currently a Monday
    If Weekday(Date) <> 2 Then Exit Sub
   
'   Run your code below
'   ...

'   Update date in cell Z1 on Sheet1 and save file
    Sheets("Sheet1").Range("Z1") = Date
    ActiveWorkbook.Save
   
End Sub
 
Upvote 0
Solution
You are welcome.
Glad I was able to help!
 
Upvote 0

Forum statistics

Threads
1,215,417
Messages
6,124,789
Members
449,188
Latest member
Hoffk036

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