Using Excel.ontime in vbscript file
When executing the below code, vbscript doesn't appear to wait for the Excel OnTime method to complete and just closes Excel. Is this expected behavior? If so, how to get around it? I know the positive branch works.
Code:
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Open(fName, 0, False) 'True = read only
If TimeValue(Now()) > TimeValue("09:55:00") Then
xlApp.Run "MyMacro"
Else
xlApp.OnTime TimeValue("10:00:00"), "MyMacro"
End If
xlBook.Close True
xlApp.Quit
Re: Using Excel.ontime in vbscript file
i would think you would need fully qualify the maro to run as this code is outside the workbook
maybe you should have the application.ontime call in a macro with in the workbook and call that procedure from your code
Re: Using Excel.ontime in vbscript file
Quote:
Originally Posted by
westconn1
maybe you should have the application.ontime call in a macro with in the workbook and call that procedure from your code
I actually tried this first and it didn't work. In the end I used WScript.Sleep() before launching Excel and it seems to work fine.