Disabling Insert Page Break

Disabling Insert Page Break

Post by Bober » Thu, 19 Aug 2004 03:55:17


I would like to disable insertpagebreak. I named a macro
InsertPageBreak and had a message box run instead. But
the macro InsertPageBreak only works for page breaks
inserted via the keyboard shortcut, not for page breaks
inserted via the Break dialog box. How can I disable page
breaks inserted via the Break dialog box (without
disabling the other break types in the dialog box)?

Thanks for any help.
 
 
 

Disabling Insert Page Break

Post by Chad DeMey » Thu, 19 Aug 2004 07:44:15

Bob,

I suspect you are the same person I replied to yesterday in
word.vba.customization, but just in case you aren't or you missed that post,
here is the solution I posted there:

Bob,

The following macro should do what you need. See comments in the macro for
a step-by-step explanation.

Sub InsertBreak()
Dim lSecs As Long

'get the count of sections in the document
lSecs = ActiveDocument.Sections.Count
'if user clicks cancel exit sub
If Dialogs(wdDialogInsertBreak).Show = 0 Then Exit Sub

'select break that was inserted and test the ASCII code of the break
character
'page or section break = 12
'column break = 14
'text wrapping break = 11
Selection.MoveLeft Extend:=wdExtend
If Asc(Selection.Text) = 12 Then
'if Asc = 12 may be page or section break, so test if section count has
increased
If ActiveDocument.Sections.Count = lSecs Then
'if not, must have been page break; undo last action
ActiveDocument.Undo
MsgBox "Sorry. Page breaks aren't allowed by this template."
Else
'otherwise, move selection back to just after the break
Selection.Collapse Direction:=wdCollapseEnd
End If
End If

End Sub

Regards,
Chad