Link to home
Start Free TrialLog in
Avatar of Paul Menhennett
Paul Menhennett

asked on

Prevent user closing word document opened with VB6

I have opened a MS-Word Document using VB6. The user can and should edit the document but I don't want them to close it from word. I want to return control to my App so I can process the document and close it cleanly. Is there a method for VB to detect the Close button on word is clicked?
Avatar of Martin Liss
Martin Liss
Flag of United States of America image

I believe you can use VB6 to determine where the user saved the document, and if you can do that you can reopen it to do your processing.
ASKER CERTIFIED SOLUTION
Avatar of Martin Liss
Martin Liss
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Paul Menhennett
Paul Menhennett

ASKER

Ark, this was very helpful and I'm sure I'll use it but Martins answer also kept everything within my project which was even better. Thanks for the rapid response
You're welcome and I'm glad I was able to help.

If you expand the “Full Biography” section of my profile you'll find links to some articles I've written that may interest you.

Marty - Microsoft MVP 2009 to 2016
              Experts Exchange MVE 2015
              Experts Exchange Top Expert Visual Basic Classic 2012 to 2015
oops, sorry, didn't notice that it's VB6 question. For VB6 it'll be:
Dim WithEvents wordApp As Word.Application
Dim allowClose as Boolean
'................
Set wordApp = New Word.Application
'..........................
Private Sub wordApp_DocumentBeforeClose(ByVal doc As Word.Document, ByRef Cancel As Boolean)
'Your conditions here to restrict closing or not
   Cancel = Not allowClose
'Validating/Saving code
   allowClose = True
'Clean up code:
   'doc.Close
   'wordApp.Quit
End Sub

Open in new window