Results 1 to 6 of 6
  1. #1
    Star Lounger
    Join Date
    Jun 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    79
    Thanks
    0
    Thanked 0 Times in 0 Posts

    API calls from VBA (Word 2003)

    Greetings All

    I'm using a API timer to periodically scan a folder. Unfortunately I don't know how to get a handle on the timer. As a result i can't kill the timer after I've finished with it so it just sits there running quite happily until I reboot the system. If someone could take pity on me and tell me how to get a handle from (or maybe on?) Word VBA, or even better would be a decent timer that works properly.

    The reason that I need a timer is that I need to create and print a PDF from Word VBA. As a consequence I have to make sure that the PDF has been created and saved befor my code tries to open/print it.

    Frank

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: API calls from VBA (Word 2003)

    Please provide more specific information.

  3. #3
    Star Lounger
    Join Date
    Jun 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    79
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: API calls from VBA (Word 2003)

    I was using the following API call;

    Public Declare Function SetTimer Lib "user32" ( _
    ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long

    and the trigger event;
    SetTimer 0, 0&, 100&, AddressOf mTimer

    Becouse I don't know how to get the windows handle from VBA I used 0 as the first parameter. The result was that I could create the timer and use it, but I couldn't kill it when I was finished. OK if you only have one or two rogue timers running but eventually ya gotta reboot.

  4. #4
    Star Lounger
    Join Date
    Jun 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    79
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: API calls from VBA (Word 2003)

    You are a Wise, hands on kinda guy.
    I'm going to try that out thanks.

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: API calls from VBA (Word 2003)

    Edited by HansV to correct some errors

    SetTimer is actually a function; you can pass the number it returns to the KillTimer API function to stop the timer:

    Public Declare Function SetTimer Lib "user32" ( _
    ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long

    Declare Function KillTimer Lib "user32" Alias "KillTimer" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long

    Public lngRetVal As Long

    ...
    lngRetVal = SetTimer(0&, 0&, 100&, AddressOf mTimer)
    ...
    If Not lngRetVal = 0 Then
    KillTimer 0&, lngRetVal
    End If

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: API calls from VBA (Word 2003)

    Please note that I have edited my reply, it contained some errors.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •