Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB/Word catching close events 1

Status
Not open for further replies.

ZOR

Technical User
Joined
Jan 30, 2002
Messages
2,963
Location
GB
Word is fast becomming a four letter word. I thought I had covered every eventuality of Word closing/Being Open/Minimised behind my application. But now I find one can close the document, say no to saving, which leaves the empty application staring at me and allows me to close it down bypassing my application quit procedure. As I cannot find any other event other than Quit/DocumentChanged after initialising Word withevents, maybe I have missed something.

Using:
Set w1 = New Word.Application
w1.Documents.Add
w1.Visible = False
Set Range = w1.ActiveDocument.Range(Start:=0, End:=0)

w1.ActiveDocument.Tables.Add Range:=Range, NumRows:=DAA + 3, NumColumns:=7 ' add table etc

Should I have done a Set xx = New Word.Document somewhere to have got a document quit procedure to use.

In my quit I am using W1.Application Quit, or W1.Quit and setting W1 = Nothing. Many thanks
 
Hi Paul, thanks for comming in. I have tried putting in a withevents xx as New Word.Document and played around, however as I am never creating a document only ever adding, I would think It's not applicable for my app.
Where do I find the DocumentBeforeClose event?, using Word 8 reference. Do I create it, ie Sub etc. Thanks

 
At form or module level declare a variable

Dim WithEvents w1 As Word.Application

Then in the code window, you can select w1 in the object list and all the application events are available in the events list.

I'm looking at teh Word 2002 object model which has a DocumentBeforeClose event.

Paul Bent
Northwind IT Systems
 
Thanks Paul. I am declaring the variable Withevents in the form declarations. When I select w1 from the object list I only get 2 events, Quit and Document Changed. I will double check my references to Word library, I am sure it's Word 8. Thanks again
 
Just to say I checked my references, and Word 8 is in there.
Must be a better way of spending life than this. Chuck the PC in the bin soon and book into the funny farm.
 
Thanks Paul, I think your'e right. Word 97 is what the client has, and what I am working with. Gone down a long road with this, it seems with MS the goals always moving. Would appreciate anyone else comming in to confirm 100% thats what my problem is. Any ideas of of a bodge solution. However thanks Paul, have a star for your efforts.
 
Think I have found the confirmation myself. Found a link that shows how limited the events are in Word 97, why I cannot solve my problems with this version. I wish I knew a way of catching the error message Automation Error 429, so at least I could fix any crashes. I think its the Remote Server message that causes the main grief. Any ideas anyone, thanks
 
Final thought - Can I specify the left/Top position of where Word Opens. I think its a Picture Box that obscures the application, and if I could control the position of Word opening, I could mask the top bit off, and add command buttons in the picture box to Print/Close the whole thing. Thanks
 
You might be able to use the SetWindowPos API to accomplish your last thought, he** you might even be able to use the SetWindowRgn API to remove the title bar by setting the display area of word. You will of course need the handle to the window to use either of these.


Good Luck
 
Thanks vb5prgrmr. My understandings on API are ziltch, in fact it was you that helped me instigate the API calls for monitoring Word being Open/Hidden/etc. Paul was exactly correct last night, I tried the app with Word 2000, and their were loads of Object events in there, and you could close and open the Word application without any Automation error problems. So I'm going to suggest the user replaces Word 97 and call it a day. Many thanks again
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top