Word not beeing started (not fast enough) 
Author Message
 Word not beeing started (not fast enough)

Hi all!

Im trying to automate Word using the following code:

CLSID clsid;
hr = CLSIDFromProgID(L"Word.Application", &clsid);


// Get the active Word application
hr = GetActiveObject(clsid, NULL, (IUnknown**)&pUnk);
  // Word is not running...
  // Start Word and get IDispatch
  hr = CoCreateInstance(clsid, NULL, CLSCTX_LOCAL_SERVER,
IID_IDispatch, (void **)&pWordApp);

  // Word is running...
  // Get IDispatch
  hr = pUnk->QueryInterface(IID_IDispatch, (void **)


// Get Documents collection
IDispatch *pDocs;

VARIANT result;
hr = AutoWrap(DISPATCH_PROPERTYGET, &result, pWordApp,
L"Documents", 0);


pDocs = result.pdispVal;

Next I call the method to open a Word document. This
works well on a fast machine (I have a Intel P4 with 384
Mb ram), but will not succeed on a slow machine (I have
tested on a P233 laptop).

I get an errormessage saying that the server is not
responding or cannot be reached or something like that.
If I hit "Retry" a few times Word then starts and
everything is fine. The reason for this (I belive) is
that it takes Word a little bit of time to acutally start
up. The call to CoCreateInstance returns but there is
still some work to do. On my fast machine speed is no
problem and Word has done all initializations needed when
the call top "Open document" comes, but when I make the
call on the slow machine Word is just no ready yet. The
reason for my suspicion is that if I repeat the procedure
one more time directly after Word is in the system cache
and I get no error message.

So my question is the following:

Is there a flag to read or a method to call, to find out
if Word is ready for calls? Of course there is a problem
here. If word is not ready the application cannot respond
to the request and you would not know, but I was hoping
for a flag to read repetedly until the application is
ready. Then I could sleep for half a second or so and
then check the flag again. I could of course just try to
call Open again and again, but I want to avoid the
errormessage beeing send to the user.

If no flag or method exist, how can this be done? Any
ideas are greatly appreciated.



Fri, 04 Mar 2005 21:53:11 GMT  
 [ 1 post ] 

 Relevant Pages 

1. Combo Box just not filling fast enough.

2. HELP - DLL's Not Unloading Fast Enough

3. picturebox control not fast enough?

4. File Reading, not fast enough!!

5. program not fast enough to show the picture?

6. picturebox control not fast enough?

7. Macro not starting when starting word 97 with /m command

8. There is not enough memory or disk space to run word

9. There is not enough memory or disk space to run word

10. entrymacro is not started if field not empty and clicked

11. Not Enough Memory

12. Not enough memory??


Powered by phpBB® Forum Software