Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VB app needs to wait for Word document to close

Posted on 1999-07-13
5
Medium Priority
?
1,159 Views
Last Modified: 2008-03-17
I am using VB6 and Word 97 and am launching Word from my VB app using CreateObject.  I programmatically open a document for the user to view.  I then want to wait for the user to close the doc before I let him continue to use my VB app, i.e. I want to suspend VB while the doc is open.

I have tried a "ping" of sorts by running a loop that gets the FullName property of the document and as long as something other than null is returned, I wait.  But when the user opens a dialog in Word (e.g. Tools/Options) the OLE conversation taking place in my loop gets locked out and VB freezes so bad I have to kill it with a Ctrl-Alt-Del.

DDE is not an option from what I can tell because from past experience we know that a similar event occurs when a dialog is open, and you must communicate over channel 0 with Word temporarily until the dialog is dismissed.  The LinkMode property (VB's DDE method) doesn't let you specify the DDE channel and so it will hang as well.  

Is there a robust, foolproof way to wait for a Word document to close from VB?
0
Comment
Question by:fenske
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 1

Expert Comment

by:Jaysin28
ID: 1524352
Have you tried

   Set wrdApp = CreateObject("Word.Application")
   
   ' Set to false when done
   wrdApp.Visible = True
   wrdapp.maximized = true

'This will put your program behind the scenes until they close the word app.  


0
 

Author Comment

by:fenske
ID: 1524353
This doesn't prevent them from Alt-Tab'ing to my app or minimizing Word to get to it.  I can't allow them to use my app again until the document is closed.
0
 
LVL 1

Expert Comment

by:dclary
ID: 1524354
Have you tried summoning Word from a VBModal form in your app...

Pseudo code here would be

Your app loads a VBmodal form (this will lock the rest of your app...)

Create the word object... get the HWND handle id

Check status of Word... when HWND handle is terminated, close VBModal form, and release control of your app back to user.


0
 

Accepted Solution

by:
tyy8 earned 600 total points
ID: 1524355
Okay here ya go...

1. Open Word and grab the window handle (very important)
2. Now use the FindWindow API in a DO...LOOP

I'd use the classname parameter in the API and leave the window caption alone (they could save it as any name they want and still have Word open and FindWindow would be fooled into thinking it's closed. Then just loop through until FindWindow returns 0 (no Word doc is open) or is not equal to your handle (another Word doc isd open but is not the one you launched). That way your program's logic is lost in this loop and cannot go forward until that Word doc is closed. Then the flow returns to your program. Also, don't forget to throw in a DoEvents into your loop (Very important). So the Word doc can have access to the processor - if you don't then you've essentially are locking up the program.
0
 

Author Comment

by:fenske
ID: 1524356
Thanks tyy8.  I actually just finished implementing a solution similar to this just before I was notified of your answer.  I used IsWindow to check to see if the handle still exists.  But since this is my first time on the Expert Exchange I'll give you the points.  Thanks again.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question