Results 1 to 3 of 3

Thread: Using Excel.ontime in vbscript file

  1. #1

    Thread Starter
    Fanatic Member VBAhack's Avatar
    Join Date
    Dec 2004
    Location
    Sector 000
    Posts
    617

    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

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    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

  3. #3

    Thread Starter
    Fanatic Member VBAhack's Avatar
    Join Date
    Dec 2004
    Location
    Sector 000
    Posts
    617

    Re: Using Excel.ontime in vbscript file

    Quote Originally Posted by westconn1 View Post
    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
  •  



Click Here to Expand Forum to Full Width