lemonhalls
Technical User
I am trying to merge files from one document into one big doc and trying to insert page number footer to every page except the first wo.
I have two places in my code where I see the word footer, in mergeDoc and insertPageNumFooter.
The footer, page number, and a text about my company seem to be inserted when mergeDoc calls insertfiles. But the original files dont' have a footer. Where are the page numbers coming from?
Sub mergeDoc()
'extracts the files from the folder and inserts them
'onto active document one after another
Dim activeDir As String
'allows user to input the name of the folder each
'time instead of defaulting the folder location
'this is more flexible in case the folder locations gets changed
activeDir = "f:\dbprinterdoc"
'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:\") 'sets the default location in the textbox
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
ActiveDocument.Sections(1).PageSetup.DifferentFirstPageHeaderFooter = True
Next i
End If
End With
End Sub
__________________
Sub insertPageNumFooter()
Dim mySection As Section
With ActiveDocument
For Each mySection In .Sections
If mySection.Index = 1 Then
.Sections(mySection.Index) _
.PageSetup.DifferentFirstPageHeaderFooter = True
ElseIf mySection.Index = 2 Then
.Sections(mySection.Index) _
.PageSetup.DifferentFirstPageHeaderFooter = True
Else
.Sections(mySection.Index) _
.PageSetup.DifferentFirstPageHeaderFooter = False
'.Sections (mySection.Index) _
'.Footers(wdHeaderFooterPrimary).PageNumbers. _
'Add PageNumberAlignment:=wdAlignPageNumberRight
End If
Next mySection
End With
End Sub
I have two places in my code where I see the word footer, in mergeDoc and insertPageNumFooter.
The footer, page number, and a text about my company seem to be inserted when mergeDoc calls insertfiles. But the original files dont' have a footer. Where are the page numbers coming from?
Sub mergeDoc()
'extracts the files from the folder and inserts them
'onto active document one after another
Dim activeDir As String
'allows user to input the name of the folder each
'time instead of defaulting the folder location
'this is more flexible in case the folder locations gets changed
activeDir = "f:\dbprinterdoc"
'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:\") 'sets the default location in the textbox
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
ActiveDocument.Sections(1).PageSetup.DifferentFirstPageHeaderFooter = True
Next i
End If
End With
End Sub
__________________
Sub insertPageNumFooter()
Dim mySection As Section
With ActiveDocument
For Each mySection In .Sections
If mySection.Index = 1 Then
.Sections(mySection.Index) _
.PageSetup.DifferentFirstPageHeaderFooter = True
ElseIf mySection.Index = 2 Then
.Sections(mySection.Index) _
.PageSetup.DifferentFirstPageHeaderFooter = True
Else
.Sections(mySection.Index) _
.PageSetup.DifferentFirstPageHeaderFooter = False
'.Sections (mySection.Index) _
'.Footers(wdHeaderFooterPrimary).PageNumbers. _
'Add PageNumberAlignment:=wdAlignPageNumberRight
End If
Next mySection
End With
End Sub