Need help with docclose

R

Raman

If I close a new document for the first time a pop appears stating whether I
want to save the document or not. What I want to accomplish is if the user
selects "yes" a userform should appear before the save dialog box appears. If
the user selects "No" the document should be closed without popping up the
userform.
 
G

Graham Mayor

Maybe something like

Sub AutoClose()
Dim sQuery As String
Start:
If Len(ActiveDocument.Path) = 0 Then
sQuery = MsgBox("Document has not been saved." & vbCr & _
"Do you wish to save the document?", vbYesNo, "Close Document")
On Error GoTo UserCancelled
If sQuery = vbYes Then
'Enter correct form name below
FormName.Show
ActiveDocument.Save
Else
If ActiveDocument.Saved = False Then
ActiveDocument.Saved = True
End If
End If
Else
If ActiveDocument.Saved = False Then
ActiveDocument.Saved = True
End If
End If
Exit Sub
UserCancelled:
MsgBox "User Cancelled", vbCritical, "Error"
GoTo Start:
End Sub


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
R

Raman

Hi Graham,

Thanks for the response. Though this is what I am trying to achieve, is it
possible to use the default office message box instead of creating a custom
message like the one suggested by you.

Regards,
Raman
 
G

Graham Mayor

Not as far as I am aware, if you want to intercept the result of that
dialog - however it should be simple enough to create a userform to emulate
that dialog box and pop that up instead of the default dialog - though
sQuery = MsgBox("Do you want to save the changes to " & _
ActiveDocument.name & Chr(63), vbYesNoCancel)
is close to the original layout.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
R

Raman

Thanks Graham.

Regards,
Raman

Graham Mayor said:
Not as far as I am aware, if you want to intercept the result of that
dialog - however it should be simple enough to create a userform to emulate
that dialog box and pop that up instead of the default dialog - though
sQuery = MsgBox("Do you want to save the changes to " & _
ActiveDocument.name & Chr(63), vbYesNoCancel)
is close to the original layout.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top