schedule excel macro to run automatically

rollingzep

Board Regular
Joined
Nov 18, 2013
Messages
224
Office Version
  1. 365
Platform
  1. Windows
Hi,

I am trying to automate the download of a large file with Task Scheduler.

<CODE>

'Input Excel File's Full Path
ExcelFilePath = "P\pgovind\LCR\LCR_Test\LCR_INFO_Test_02.xlsm"

'Input Module/Macro name within the Excel File
MacroPath = "HQLA_MTG_Pools.HQLA_MTG_Pools"

'Create an instance of Excel
Set ExcelApp = CreateObject("Excel.Application")

'Do you want this Excel instance to be visible?
ExcelApp.Visible = True 'or "False"

'Prevent any App Launch Alerts (ie Update External Links)
ExcelApp.DisplayAlerts = False



'Open Excel File
Set wb = ExcelApp.Workbooks.Open(ExcelFilePath)

'Execute Macro Code
ExcelApp.Run MacroPath

'Save Excel File (if applicable)
wb.Save

'Reset Display Alerts Before Closing
ExcelApp.DisplayAlerts = True

'Close Excel File
wb.Close

</CODE>

In the Task Scheduler, I set up the path Action

"C:\Windows\System32\cscript.exe"
and optional arguments

"\\P\pg\LCR\LCR_Test\Macro Launcher.vbs"

But it is not running when I tried with a scheduled time.

Is my macro path correct? MacroPath = "HQLA_MTG_Pools.HQLA_MTG_Pools. The module name and macro are the same.
Or is the space creating issues in Macro Launcher.vbs
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Hi,

I am trying to automate the download of a large file with Task Scheduler.

<CODE>

'Input Excel File's Full Path
ExcelFilePath = "P\pgovind\LCR\LCR_Test\LCR_INFO_Test_02.xlsm"

'Input Module/Macro name within the Excel File
MacroPath = "HQLA_MTG_Pools.HQLA_MTG_Pools"

'Create an instance of Excel
Set ExcelApp = CreateObject("Excel.Application")

'Do you want this Excel instance to be visible?
ExcelApp.Visible = True 'or "False"

'Prevent any App Launch Alerts (ie Update External Links)
ExcelApp.DisplayAlerts = False



'Open Excel File
Set wb = ExcelApp.Workbooks.Open(ExcelFilePath)

'Execute Macro Code
ExcelApp.Run MacroPath

'Save Excel File (if applicable)
wb.Save

'Reset Display Alerts Before Closing
ExcelApp.DisplayAlerts = True

'Close Excel File
wb.Close

</CODE>

In the Task Scheduler, I set up the path Action

"C:\Windows\System32\cscript.exe"
and optional arguments

"\\P\pg\LCR\LCR_Test\Macro Launcher.vbs"

But it is not running when I tried with a scheduled time.

Is my macro path correct? MacroPath = "HQLA_MTG_Pools.HQLA_MTG_Pools. The module name and macro are the same.
Or is the space creating issues in Macro Launcher.vbs
Do I need to declare the wb, ExcelFilePath , MacroPath and ExcelApp in the .VBS script using Dim?
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
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