Schedule SAP Macros With The Task Scheduler

Table of Contents

1. Create the VBS file

If you want to schedule only the SAP macro (VBS file) and not the VBA macro (Excel file), you can go directly to the STEP 2.

Otherwise, create a New Text Document :

Copy paste the following code in the Text Document :

				
					'Input Excel File's Full Path
ExcelFilePath = "C:\Users\Lucas\Desktop\sap_macro_schedule_exemple.xlsm"
'Input Module/Macro name within the Excel File
MacroPath = "macro_module.schedule_sap_macro"
'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
'End instance of Excel
ExcelApp.Quit
'Leaves an onscreen message!
MsgBox "Your Automated Task successfully ran at " & TimeValue(Now), vbInformation
				
			

Save the Text Document in .txt

Change the extension to .vbs by renaming it :

2. Open the Task Scheduler

  • Clic on the icon on the taskbar as shown below

  • Click on “Create Task

3. General options of the Task Scheduler

  • Name your scheduled action

  • Fill the description part

4. Trigger options of the Task Scheduler

Go to the Triggers tab and click on new

Select the dates and times that you want your macro to run

Go to the Actions tab and click on New :

  • Under Program/ script, put : C:\Windows\System32\cscript.exe

  • In the field Add arguments, put the path of your Excel file

Articles liés

Macros SAP GUI SANS CODER ?

Apprenez à enregistrer vos propres Macros SAP GUI en 3 étapes simples et SANS CODER Fonctionne quelle que soit votre version de SAP (tant que…