Run a macro on last day of each month at midnight

NZAS

Board Regular
Joined
Oct 18, 2012
Messages
117
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hi
I have a file that has a Mracro (Macro2) to refresh the data and a pivot table.
I want to be able to automatically run this macro on the last day of each month at midnight. The file would not be open at that time this would need to be run, so will need to open the file on the last day of each month at midnight "00:00", and run the macro (macro2), when done then saveas with a the new file eg 18 Nov Monthend (year, month, Monthend) when closing the file.
This then can be opened any time to veiw the data which is a snapshot of data at month end at midnight.
Cheers
NZAS
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
You can use the windows Task Scheduler to kick off a process on the last day of each month at a specific time.
The process can be either a macro enabled workbook with a macro that starts when the workbook is opened, or
the process could be a "vbs" script that opens the workbook and runs a specific macro.


The vbs script file could be something like:

Code:
Dim fso, oExcel, oWorkbook, strXlsName, strXlsPath

Set fso = CreateObject("Scripting.FileSystemObject")
Set oExcel = CreateObject("Excel.Application")

strXlsPath = fso.GetAbsolutePathName(".") & "\YOUR_WORKBOOK.xlsm"
oExcel.Workbooks.Open strXlsPath, , False
Set oWorkbook = oExcel.ActiveWorkbook

oWorkbook.Application.Visible = True
oWorkbook.Application.Run "YOUR_MACRO_TO_RUN"

'Wait while Excel script runs
WScript.Sleep 15000
oWorkbook.Close True 'save changes
'your macro should be programmed to do the saving with the new name.

oExcel.Application.Quit

Set fso = Nothing
Set oWorkbook = Nothing
Set oExcel = Nothing
 
Upvote 0
It is a macro enable workbook where the macro runs when the workbook has been opened
 
Upvote 0
Then you can set up a Task in the Task Scheduler to open your workbook on the last day of every month at midnight.
 
Upvote 0
Solution

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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