• API calls from VBA (Word 2003)

    Author
    Topic
    #437076

    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

    Viewing 0 reply threads
    Author
    Replies
    • #1038069

      Please provide more specific information.

      • #1038496

        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.

        • #1038502

          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

          • #1038527

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

            • #1038529

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

    Viewing 0 reply threads
    Reply To: API calls from VBA (Word 2003)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: