Thanks, Greg. I can almost get this to work, but I must be doing something
wrong. Here's the code I tried based on your suggestion, including a part of
my macro that generates the error requiring the document to be in "print
layout" view before it will run:
Sub MessageBox()
On Error Resume Next 'Defer error handling.
Err.Raise 5622 'Generate an "Overflow" error.
If Err.Number = 5894 Then
MsgBox "You must change your page view. Go to the View menu and choose
'Page Layout'. Then run the macro again."
End If
Err.Clear
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Selection.WholeStory
Selection.Delete
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
Selection.WholeStory
Selection.Delete
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
End Sub
This however, seems to generate the custom dialog box regardless of what
error Word generates, and regardless of whether an error was generated at
all. Even if I am in a document that has the correct view settings to run
the main part of the macro, I get the error message. And even if my form is
locked, which normally produces a different error message number, I get this
same custom dialog box.
> Dawn,
>
[quoted text clipped - 10 lines]
> Err.Clear
> End Sub
Greg Maxey - 29 Apr 2005 01:50 GMT
Dawn
Well, you where generating the error after the fact :-)
Consider:
Sub MessageBox()
On Error GoTo Handler
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Selection.WholeStory
Selection.Delete
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
Selection.WholeStory
Selection.Delete
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
Exit Sub
Handler:
If Err.Number = 5894 Then
MsgBox "You must change your page view. Go to the View menu and choose
" _
& """Page Layout"". Then run the macro again."
End If
Err.Clear
End Sub
Please remember that I am not a Err handler wizard. What I proposed will do
what you ask, but there is probably room for improvement.
Again, there is no need for generating an error. How about:
Sub NoNeedForMessageBox()
Dim Protection As Long
Dim View As Long
'Get the current protection and view type
Protection = ActiveDocument.ProtectionType
View = ActiveWindow.View
'Unprotect the document
'On Error GoTo Ignore
'ActiveDocument.Unprotect
'Ignore: Err.Clear
'Set the view to PrintPreview
ActiveWindow.View.Type = wdPrintView
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Selection.WholeStory
Selection.Delete
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
Selection.WholeStory
Selection.Delete
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
'Reapply Users preferred view
ActiveWindow.View.Type = View
'Reapply users protection type
'On Error GoTo IgnoreProtect
'ActiveDocument.Protect Type:=Protection, NoReset:=True
'IgnoreProtect: Err.Clear
End Sub

Signature
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.
> Thanks, Greg. I can almost get this to work, but I must be doing
> something wrong. Here's the code I tried based on your suggestion,
[quoted text clipped - 43 lines]
>> Err.Clear
>> End Sub