DaveyCricket
Technical User
I'm a complete VB noobie.
I'm trying to create a macro for Word that will create headers from Page 3 onward, but leave Pages 1 and 2 without. I've created the one below by simply recording the macro and taking all the steps I would normally take to make this possible, (Insert>Break>Next Page>View>Header Footer>Show Next>Same as Previous, etc.)
I also should note that I've added a couple Inputboxes to type in some text, though this error occurs with or without those prompts.
Here's the code:
Selection.InsertBreak Type:=wdSectionBreakNextPage
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
ActiveWindow.ActivePane.View.NextHeaderFooter
Selection.HeaderFooter.LinkToPrevious = Not Selection.HeaderFooter. _
LinkToPrevious
Company = InputBox("Insert Company Name ALL CAPS")
Selection.TypeText Text:=Company
Selection.TypeParagraph
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldDate
Selection.TypeParagraph
Quote = InputBox("Type Quote Number")
Selection.TypeText Text:="Quote No. "
Selection.TypeText Text:=Quote
Selection.TypeParagraph
Selection.TypeText Text:="Page "
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldPage
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
End Sub
The error occurs on both these lines:
ActiveWindow.ActivePane.View.NextHeaderFooter
Selection.HeaderFooter.LinkToPrevious = Not Selection.HeaderFooter. _
LinkToPrevious
When I ' out those two lines, the macro works beautifully, but populates the Headers for Page 1 and Page 2, but none of the ones afterward. So, it's doing exactly the OPPOSITE of what I want it to.
If anyone can tell me what I'm doing wrong, or even how to accomplish what I'm trying to, it'd be greatly appreciated.
And please, talk to me like I'm a 2 year old. Because I have pretty much no idea what I'm doing.
Thanks!
I'm trying to create a macro for Word that will create headers from Page 3 onward, but leave Pages 1 and 2 without. I've created the one below by simply recording the macro and taking all the steps I would normally take to make this possible, (Insert>Break>Next Page>View>Header Footer>Show Next>Same as Previous, etc.)
I also should note that I've added a couple Inputboxes to type in some text, though this error occurs with or without those prompts.
Here's the code:
Selection.InsertBreak Type:=wdSectionBreakNextPage
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
ActiveWindow.ActivePane.View.NextHeaderFooter
Selection.HeaderFooter.LinkToPrevious = Not Selection.HeaderFooter. _
LinkToPrevious
Company = InputBox("Insert Company Name ALL CAPS")
Selection.TypeText Text:=Company
Selection.TypeParagraph
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldDate
Selection.TypeParagraph
Quote = InputBox("Type Quote Number")
Selection.TypeText Text:="Quote No. "
Selection.TypeText Text:=Quote
Selection.TypeParagraph
Selection.TypeText Text:="Page "
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldPage
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
End Sub
The error occurs on both these lines:
ActiveWindow.ActivePane.View.NextHeaderFooter
Selection.HeaderFooter.LinkToPrevious = Not Selection.HeaderFooter. _
LinkToPrevious
When I ' out those two lines, the macro works beautifully, but populates the Headers for Page 1 and Page 2, but none of the ones afterward. So, it's doing exactly the OPPOSITE of what I want it to.
If anyone can tell me what I'm doing wrong, or even how to accomplish what I'm trying to, it'd be greatly appreciated.
And please, talk to me like I'm a 2 year old. Because I have pretty much no idea what I'm doing.
Thanks!