Is there a way of opening a specific workbook, running a macro, an saving the workbook automatically at certain times?

Coyotex3

Active Member
Joined
Dec 12, 2021
Messages
496
Office Version
  1. 365
Platform
  1. Windows
Wondering if Excel can do this. Let's say I have a workbook named "Coyote" on my donwloads folder. Could I tell Excel through VBA to open that workbook run the macro "Speed of Light" and then save the workbook like every monday at 9:30am for example?

Or is excel able to do anything remotely close to this?
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
To run a macro contained in another workbook:

VBA Code:
Application.Run "'Coyote.xlsm'!Speed of Light"

As far as saving that workbook on a schedule, Look into Application.OnTime ;)
 
Upvote 0
To run a macro contained in another workbook:

VBA Code:
Application.Run "'Coyote.xlsm'!Speed of Light"

As far as saving that workbook on a schedule, Look into Application.OnTime ;)
Hmmm it is telling me that it can't find the file. It is looking in sharepoint for some reason. After that I get 1004 error Application defined or Object-defined error.

I will look into Application.OnTime. THANK YOU!
 
Upvote 0
Here is more complete sample:

VBA Code:
Sub OpenTest()
'
    DownloadFolderPath = Environ$("USERPROFILE") & "\Downloads\"        ' Get Path to Downloads folder
'
    Workbooks.Open DownloadFolderPath & "Coyote.xlsm"                   ' Open desired workbook in that folder path
'
    Application.Run "'Coyote.xlsm'!Speed of Light"                      ' Run macro from within that workbook
End Sub
 
Upvote 0
Solution
Here is more complete sample:

VBA Code:
Sub OpenTest()
'
    DownloadFolderPath = Environ$("USERPROFILE") & "\Downloads\"        ' Get Path to Downloads folder
'
    Workbooks.Open DownloadFolderPath & "Coyote.xlsm"                   ' Open desired workbook in that folder path
'
    Application.Run "'Coyote.xlsm'!Speed of Light"                      ' Run macro from within that workbook
End Sub
Almost there. I was able to open the workbook but still getting runtime 1004 error.
 
Upvote 0
Worked fine for me.

You do realize that you can't have spaces in a Macro name right? You would have to name the macro, for example, SpeedOfLight
 
Upvote 0
Worked fine for me.

You do realize that you can't have spaces in a Macro name right? You would have to name the macro, for example, SpeedOfLight
This is what I have

VBA Code:
Sub OpenTest()
'
    DownloadFolderPath = Environ$("USERPROFILE") & "\Downloads\"        ' Get Path to Downloads folder
'
    Workbooks.Open DownloadFolderPath & "SpeedTest.xlsx"                   ' Open desired workbook in that folder path
'
    Application.Run "'SpeedTest.xlsx'!SpeedOfLight"                      ' Run macro from within that workbook
End Sub

Does it have to be a macro enabled workbook?
 
Upvote 0
Wondering if Excel can do this. Let's say I have a workbook named "Coyote" on my donwloads folder. Could I tell Excel through VBA to open that workbook run the macro "Speed of Light" and then save the workbook like every monday at 9:30am for example?

Or is excel able to do anything remotely close to this?
One thing I have often done is to either place/or call my code to run in the "Workbook_Open" event procedure in VBA. This will cause the macro to run automatically upon opening the file.

Then, I will use something like Windows Scheduler to automatically open the file at my desired time and day, which will open the file, and then the Workbook_Open event will cause my code to run.

If you use this method, just be sure to add a line of code at the bottom of the "Workbook_Open" event to automatically close the workbook too.

There are other similar methods you can find with a simple Google search, like this one:
 
Upvote 0
Of course. You can't run a macro in a non macro enabled workbook.
Basics.. Completely overthought it.
One thing I have often done is to either place/or call my code to run in the "Workbook_Open" event procedure in VBA. This will cause the macro to run automatically upon opening the file.

Then, I will use something like Windows Scheduler to automatically open the file at my desired time and day, which will open the file, and then the Workbook_Open event will cause my code to run.

If you use this method, just be sure to add a line of code at the bottom of the "Workbook_Open" event to automatically close the workbook too.

There are other similar methods you can find with a simple Google search, like this one:
Thank you Joe.

Will look into this link!
 
Upvote 0

Forum statistics

Threads
1,214,790
Messages
6,121,608
Members
449,038
Latest member
apwr

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