Results 1 to 3 of 3
  1. #1
    4 Star Lounger
    Join Date
    Jan 2002
    Location
    London, Gtr London, England
    Posts
    416
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Wait until end of macro (WORD 97/2000)

    Hi,

    I have a word 'situation' that needs correcting urgently. In my word document, a macro is called to create a PDF file. The macro returns immediately after starting the PDF file creation process 'in the background'. What I would like it to do is NOT return from a macro until the PDF file is created. Is this possible? Can we somehow tell the macro complete & only return when it finishes?

    The other question is (if above is not possible), is there a way to check for a file (PDF file) to exists in a directory and wait until it does exist before proceeding further? What I mean is
    1. Call the macro to create the PDF file
    2. Wait until the PDF file is created - somehow check on the hard disk to exist
    3. If the PDF file is created/exists
    do further processing
    endif

    Thanks in advance.

    Robie
    Thanks.
    Robie

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

    Re: Wait until end of macro (WORD 97/2000)

    You could use code like this to wait for the file:

    Function WaitForFile(strFilename As String, datLastTime As Date) As Boolean
    Do While Now <= datLastTime
    If Dir(strFilename) <> "" Then
    WaitForFile = True
    Exit Do
    End If
    DoEvents
    Loop
    End Function

    This function will wait until at most datLastTime and return True if strFilename exists, False otherwise.

    Call it like this to check if C:ExcelTest.pdf has been created and wait for at most 1 minute:

    If WaitForFile("C:ExcelTest.pdf", Now + TimeSerial(0, 1, 0)) = True Then
    ' File created
    ...
    Else
    ' File missing
    MsgBox "File not found.", vbExclamation
    End If

  3. #3
    4 Star Lounger
    Join Date
    Jan 2002
    Location
    London, Gtr London, England
    Posts
    416
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Wait until end of macro (WORD 97/2000)

    Thank You.

    Seems very useful. I shall try it out.

    Robie.
    Thanks.
    Robie

Posting Permissions

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