Word 2007 macro problem-different first page header

G

George T

I have a very simple macro for formatting documents to fit our letterhead.
I cannot get the "different first page" setting into the macro.

When the macro runs, the header for subsequent pages appears on the first
page. The act of checking the "different first page" setting is not captured
when the macro steps are recorded. How do I insert that setting into the
macro?

CODE:

Sub Letter()
'
' Letter Macro
'
'
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.InsertDateTime DateTimeFormat:="dddd, MMMM dd, yyyy", _
InsertAsField:=False, DateLanguage:=wdEnglishUS, CalendarType:= _
wdCalendarWestern, InsertAsFullWidth:=False
Selection.TypeParagraph
Selection.TypeText Text:="Page "
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
"PAGE \* Arabic ", PreserveFormatting:=True
Selection.TypeText Text:=" of "
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
"NUMPAGES \* Arabic ", PreserveFormatting:=True
Selection.TypeParagraph
Selection.TypeText Text:="___________________________ "
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
....
HERE IS WHERE I THOUGHT THERE WOULD BE SOME COMMAND REFLECTING THE
"DIFFERENT FIRST PAGE" SELECTION BUT THERE IS NOT.
.....
Selection.TypeParagraph
Selection.TypeParagraph
Selection.TypeParagraph
Selection.TypeParagraph
Selection.TypeParagraph
Selection.TypeParagraph
Selection.TypeParagraph
Selection.TypeParagraph
Selection.TypeParagraph
Selection.TypeParagraph
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
Selection.InsertDateTime DateTimeFormat:="MMMM d, yyyy", InsertAsField:= _
False, DateLanguage:=wdEnglishUS, CalendarType:=wdCalendarWestern, _
InsertAsFullWidth:=False
Selection.TypeParagraph
Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft
Selection.TypeParagraph
Selection.TypeParagraph
Selection.TypeParagraph
Selection.TypeParagraph
End Sub
 
D

drichird

Hi George

I didn't completely understand from your macro what you were looking for in
the headers after the first page, but this modification i tested puts your
first page header info in first page and then just prints 'All other pages'
for the other headers. Document should be multipage, or just add a page
break programmatically. I am assuming you are not looking for different
odd/even page headers, which is yet another option.

Hope this helps.

Rich

Sub Letter()
'
' Letter Macro
'
'
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

' specify that the document has a different first page header
ActiveDocument.PageSetup.DifferentFirstPageHeaderFooter = True

ActiveWindow.ActivePane.View.SeekView = wdSeekFirstPageHeader
Selection.InsertDateTime DateTimeFormat:="dddd, MMMM dd, yyyy", _
InsertAsField:=False, DateLanguage:=wdEnglishUS, CalendarType:= _
wdCalendarWestern, InsertAsFullWidth:=False
Selection.TypeParagraph
Selection.TypeText Text:="Page "
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
"PAGE \* Arabic ", PreserveFormatting:=True
Selection.TypeText Text:=" of "
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
"NUMPAGES \* Arabic ", PreserveFormatting:=True
Selection.TypeParagraph
Selection.TypeText Text:="___________________________ "
'ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
'...
'HERE IS WHERE I THOUGHT THERE WOULD BE SOME COMMAND REFLECTING THE
'"DIFFERENT FIRST PAGE" SELECTION BUT THERE IS NOT.
'....
'do something with all the other (not first page) headers
'first page header means just that
'primary header means all the others after page 1
'document must already have more than 1 page, or just insert a page break
ActiveWindow.ActivePane.View.SeekView = wdSeekPrimaryHeader
Selection.TypeText Text:="All other pages "
End Sub
 
G

George T

Thanks.
Adding this line you provided
ActiveDocument.PageSetup.DifferentFirstPageHeaderFooter = True
right after the header creation details made the macro run exactly the way I
wanted.
 

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

Similar Threads

Mail merge macro duplication 2
4198 debug 0
create macro? 4
Macro to fix header 0
Worked in 2003, not in 2007 6
double merge 2
Macro to place Insert information into a footer 4
Creating a macro in Outlook 1

Top