Pause code while waiting for document to open

G

GrPacker

I have a document that calls another document to open, then it starts
copying over some form field data. I have tried using the Sleep API
to wait for the document to open before continuing on with the code,
but this only makes Word hang and then when it resumes, the document
continues opening and the code tries to run before it is open (errors
out).

Would it be possible to write an If statement to verify that the
document is fully opened before proceeding. Any better options?

Thanks again for your help!
 
H

Helmut Weber

Hi,

maybe like that:

Sub Test660q()
Dim t As Double
t = Timer
Dim oDcm As Document
Set oDcm = Documents.Open("c:\test\006.doc")
ActiveDocument.Repaginate
MsgBox Timer - t
End Sub

The program continues after repaginate is fully executed.

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
 
G

Gordon Bentley-Mix at news.microsoft.com

You might also want to investigate the OnTime method. According to the VBA
help, it "tarts a background timer that runs a macro at a specified time".
I've used it before with the DateAdd function to pause code execution for a
few seconds to allow another process to run before executing my VBA. You may
be able to adapt it your particular situation.
--
Cheers!

Gordon Bentley-Mix
Word MVP

Please post all follow-ups to the newsgroup.

Read the original version of this post in the Office Discussion Groups - no
membership required!
 
T

Tony Jollans

Where are you running this code from? And where are you opening the document
from? It should not normally behave like this if simply opening a document
while running inside Word.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top