Wednesday, November 14, 2007

Calling Macro in QTP or VBS

'Run Macros from VBS

Function callMacro(strFilePath)
Set XLApp = CreateObject("Excel.Application")
XLApp.Application.DisplayAlerts = False
Set XLBook = XLApp.Workbooks.Open(strFilePath, readOnly=False)
XLBook.Sheets("Sheet1").Activate
'call Excel macro
XLApp.run "Macro1"
XLBook.Save
XLApp.Quit
Set XLBook = nothing
Set XLApp = nothing
End Function