Below is an old macro we've used for years that adds a second page header to letters with more than one page. It's worked well until we upgraded some users for Word 2003 to Word 2007. Now somehow I have a couple users who occasionally someone get a continuous section break on the line with the bookmark and this causes the macro to crash with a run-time error 5684. The bookmark is suppose to be on the line where the addressee's name is located. On their letters it's the next line below the bookmark. The macro goes to the bookmark and tries to copy the line and freaks because it includes a section break.
How to work around this? One idea I had was to figure out how to write into the macro to look at the content of the line on which the bookmark is located. If there's no text to move down one line before capturing content and moving forward. No idea how to write that If statement or if it's even possible. The other idea I had was for add something where the macro would look at the letter and if it sees more than one continuous section break (there's one next to the date that needs to stay there) to delete the line bookmark line and move forward. I like the first idea of analyzing the content of the line then for the macro to make a decision over the second.
Where do I go from here?
Code:Sub ltrSecondPageHeader() On Error GoTo -1: On Error GoTo Trap WordBasic.FileSummaryInfo Update:=1 Dim dlg As Object: Set dlg = WordBasic.DialogRecord.DocumentStatistics(False) WordBasic.CurValues.DocumentStatistics dlg If dlg.Pages = "1" Then WordBasic.MsgBox "This letter does not need a second page header" + Chr(13) + "because it is only one page long.", " ", 48 GoTo OutOfHere End If Selection.GoTo What:=wdGoToBookmark, Name:="EnvStart" Selection.Find.ClearFormatting With Selection.Find .Text = "" .Replacement.Text = "" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.EndKey Unit:=wdLine, Extend:=wdExtend Selection.Copy Selection.EndKey Unit:=wdStory If ActiveWindow.View.SplitSpecial <> wdPaneNone Then ActiveWindow.Panes(2).Close End If If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _ ActivePane.View.Type = wdOutlineView Then ActiveWindow.ActivePane.View.Type = wdPrintView End If ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader Selection.PasteAndFormat (wdPasteDefault) Selection.InsertDateTime DateTimeFormat:="MMMM d, yyyy", InsertAsField:= _ False, DateLanguage:=wdEnglishUS, CalendarType:=wdCalendarWestern, _ InsertAsFullWidth:=False Selection.TypeParagraph Selection.TypeText Text:="Page " Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldPage Selection.TypeText Text:=vbTab Selection.HomeKey Unit:=wdLine Selection.EndKey Unit:=wdLine, Extend:=wdExtend If Selection.Font.Underline = wdUnderlineNone Then Selection.Font.Underline = wdUnderlineSingle Else Selection.Font.Underline = wdUnderlineNone End If Selection.EndKey Unit:=wdLine Selection.TypeParagraph Selection.TypeParagraph If ActiveWindow.View.SplitSpecial <> wdPaneNone Then ActiveWindow.Panes(2).Close End If If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _ ActivePane.View.Type = wdOutlineView Then ActiveWindow.ActivePane.View.Type = wdPrintView End If ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument Selection.HomeKey Unit:=wdStory GoTo NoMore OutOfHere: WordBasic.MsgBox "Second Page Header Cancelled!", " ", 48 GoTo Complete NoMore: GoTo Complete Trap: If Err.Number = 102 Then WordBasic.MsgBox "An Error Occurred - Header Cancelled!", " ", 48 Err.Number = 0 GoTo Complete ElseIf Err.Number = 509 Then WordBasic.MsgBox "An Error Occurred - Header Cancelled!", " ", 48 Err.Number = 0 GoTo Complete Else Error Err.Number End If Complete: WordBasic.MsgBox "Second Page Header Complete.", " ", 48 End Sub



