Log in

View Full Version : Closing Word without Forms



RickSprague
08-23-2010, 04:54 AM
I have a problem. I have two documents, Doc1 and Doc2. Doc2 has a Class Module with the following code:

Option Explicit
Public WithEvents App As Word.Application
Private Sub App_DocumentBeforeClose(ByVal Doc As Document, Cancel As Boolean)
Dim strInput As String
If ActiveDocument.ReadOnly Then Exit Sub

frmInputBox.Show

End Sub

I need to open Doc1, run some code that includes opening Doc2. Doc1 then saves Doc2 and closes it. But, of course, when Doc2 closes the form frmInputBox opens. I need to close Doc2 with firing the BeforeClose event.

Any help very much appreciated.

fumei
08-25-2010, 05:57 PM
" But, of course, when Doc2 closes the form frmInputBox opens. I need to close Doc2 with firing the BeforeClose event."

Ummm, yes, as that is what you are telling it to do.

Please clarify. ALL instructions valid within BeforeClose are executed, and then...it closes. So what - exactly - are you wanting to happen?

If you do NOT want frmInputBox.Show to execute, add some logic that prevents it from executing. As it is, if Doc2 is ReadOnly, nothing else happens, and the document closes.

If it is NOT read-only, frmInputBox Shows.