How to close read-only file when Document_Close Event raises error


W

wal

Vista
Office 2007

I have a Document_Close Event sub in ThisDocument in Normal that saves
a backup copy of the file in a second location. The main code starts
with ActiveDocument.Save to ensure that the main version of the
document is properly saved before the backup version is.

A problem occurs when I want to close a read-only file without saving
it as anything; just close it.

Before the ActiveDocument.Saved line, I have the following code:

If ActiveDocument.ReadOnly = True Then
On Error GoTo Handler
Dim rYesponse
rYesponse = MsgBox("[instructions: Press OK to close without
saving; press Cancel to go back and save with a name.]", 33, "Read-
only file!!")
If rYesponse = vbOK Then
ActiveDocument.Saved = True [This line doesn't cause problems;
probably superfluous]
ActiveDocument.Close [***ERROR 4198 OCCURS HERE if "on error
go to handler" line is omitted.***]
Else:
Exit Sub
On Error GoTo 0
End If
On Error GoTo 0
End If

At the Handler, I have:

Handler:
If Err.Number = 4198 Then
ActiveDocument.Close
End If

The problem is, at ActiveDocument.Close in the Handler, the error 4198
dialog comes up.

So, how can I close the document without further ado? Thanks.
 
Ad

Advertisements


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