|
-
Feb 8th, 2012, 03:49 PM
#1
Thread Starter
Fanatic Member
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
-
Feb 9th, 2012, 05:30 AM
#2
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
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Feb 10th, 2012, 02:56 PM
#3
Thread Starter
Fanatic Member
Re: Using Excel.ontime in vbscript file
 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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|