inserting footer to first page of inserted file but not of entire doc

S

sals

Hi,
I have this code to insert the page number/footer to my document.

This document begins with a cover page, then a TOC is inserted and
then followed by files inserted one after another.

what is happening:
page number footer is on every page except on the TOC page and on the
first page of each inserted file

what I would like to happen:
page number footer on every page except cover page and TOC page.

background:
these sections are seperated by a section break (next page), ie cover,
section break (sb), TOC, sb, inserted file 1 (if), sb, if2, sb, if3
etc

Any idea how I can modify the code to have the page number show up on
the first page of every inserted file?

Thanks!
___________________________________________
Sub mergeDoc()

'Dim activeDir As String

activeDir = InputBox _
(Prompt:="Enter the path where the files to be merged are stored.
End with '\', for example U:\SYS\PSMP-PGSPS\", _
Title:="Path", Default:="U:\")

With Application.FileSearch
.LookIn = activeDir 'folder with old files
End With

'move to the end of the document to insert files
Selection.EndKey Unit:=wdStory, Extend:=wdMove

With Application.FileSearch
.NewSearch
.LookIn = activeDir
.SearchSubFolders = False
.FileName = "*.doc"
.MatchTextExactly = False

'retrieves the files in alphabetical order
If .Execute(SortBy:=msoSortByFileName, _
sortOrder:=msoSortOrderAscending) > 0 Then

For i = 1 To .FoundFiles.Count
Selection.TypeParagraph
Selection.InsertFile FileName:=.FoundFiles(i),
Range:="", _
ConfirmConversions:=False, Link:=False,
Attachment:=False

Selection.Find.ClearFormatting
With Selection.Find
.Text = "Printer Friendly Version"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
End With
Selection.Find.Execute
Selection.HomeKey Unit:=wdLine
Selection.MoveDown Unit:=wdLine, Count:=4,
Extend:=wdExtend
Selection.Delete Unit:=wdCharacter, Count:=1

Selection.InsertBreak Type:=wdSectionBreakNextPage
ActiveDocument.Sections(1).PageSetup.DifferentFirstPageHeaderFooter
= True
HeaderFooter.LinkToPrevious
With ActiveDocument.Sections(1)

..Footers(wdHeaderFooterPrimary).PageNumbers.Add _
PageNumberAlignment:=wdAlignPageNumberRight, _
FirstPage:=False
End With

margin
Next i

'Remove Final Section Break
Selection.EndKey Unit:=wdStory
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1

Else
MsgBox "There were no files found to concatenate."
End If
End With
End Sub
 
D

DA

Hi Sals

What you're doing is setting up section 1 correctly, but
ignoring all your other doc sections.

I'd restructure you code so you can break up the tasks of
inserting and formatting. Try something like this:

- Insert your files first
- write a new sub that gets executed after you've done
the above and do all your formatting.
- For your page numbers, cycle through each section in
your doc. For section 1, leave your code as is, but for
subsequent sections set your
DifferentFirstPageHeaderFooter value to false.

Example:
---------
Dim mySection As Section

With ActiveDocument
For Each mySection In .Sections
If mySection.Index = 1 Then
.Sections(mySection.Index) _
.PageSetup.DifferentFirstPageHeaderFooter = True
Else
.Sections(mySection.Index) _
.PageSetup.DifferentFirstPageHeaderFooter = False
End If
Next mySection
End With
---------

Best of luck,
Dennis

-----Original Message-----
Hi,
I have this code to insert the page number/footer to my document.

This document begins with a cover page, then a TOC is inserted and
then followed by files inserted one after another.

what is happening:
page number footer is on every page except on the TOC page and on the
first page of each inserted file

what I would like to happen:
page number footer on every page except cover page and TOC page.

background:
these sections are seperated by a section break (next page), ie cover,
section break (sb), TOC, sb, inserted file 1 (if), sb, if2, sb, if3
etc

Any idea how I can modify the code to have the page number show up on
the first page of every inserted file?

Thanks!
___________________________________________
Sub mergeDoc()

'Dim activeDir As String

activeDir = InputBox _
(Prompt:="Enter the path where the files to be merged are stored.
End with '\', for example U:\SYS\PSMP-PGSPS\", _
Title:="Path", Default:="U:\")

With Application.FileSearch
.LookIn = activeDir 'folder with old files
End With

'move to the end of the document to insert files
Selection.EndKey Unit:=wdStory, Extend:=wdMove

With Application.FileSearch
.NewSearch
.LookIn = activeDir
.SearchSubFolders = False
.FileName = "*.doc"
.MatchTextExactly = False

'retrieves the files in alphabetical order
If .Execute(SortBy:=msoSortByFileName, _
sortOrder:=msoSortOrderAscending) > 0 Then

For i = 1 To .FoundFiles.Count
Selection.TypeParagraph
Selection.InsertFile FileName:=.FoundFiles(i),
Range:="", _
ConfirmConversions:=False, Link:=False,
Attachment:=False

Selection.Find.ClearFormatting
With Selection.Find
.Text = "Printer Friendly Version"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
End With
Selection.Find.Execute
Selection.HomeKey Unit:=wdLine
Selection.MoveDown Unit:=wdLine, Count:=4,
Extend:=wdExtend
Selection.Delete Unit:=wdCharacter, Count:=1
(1).PageSetup.DifferentFirstPageHeaderFooter
= True
HeaderFooter.LinkToPrevious
With ActiveDocument.Sections(1)

..Footers(wdHeaderFooterPrimary).PageNumbers.Add _
PageNumberAlignment:=wdAlignPageNumberRight, _
 

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

Top