[dba-Tech] VBS question

Susan Harkins ssharkins at gmail.com
Fri Jun 21 08:08:07 CDT 2019


Do any of you use .vbs scripts to interact with an Excel workbook? I've
written one to run from Windows Task Scheduler. It simply triggers a print
macro (prints a PivotTable) daily. 

The macro in Excel works. The task is running, but the PivotTable never
prints. This is rather new to me, so I'm sure it's a simple fix, probably in
one of the referencing statements. Can someone take a look? I've tried
several variations of referencing the macro. 

'.vbs file to print Excel PivoTable1.xlsm at 8am daily.

'Path to workbook.
strPath = "C:\Documents\PivotTable1.xlsm" 

'Macro name.
strMacro = "PrintUpdatedPivotTable" 

'Create an Excel instance.
Set objApp = CreateObject("Excel.Application") Set objwb =
objExcel.Workbooks.Open(strPath) objApp.Visible = True

objApp.Run strMacro
objwb.Close
objApp.Quit 

'Scheduled task completed. 
MsgBox strPath & " " & strMacro & " PivotTable printed successfully",
vbInformation

Susan H. 



More information about the dba-Tech mailing list