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
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