CPForecast
Programmer
Hello,
I am working on a macro that will string a series of files together in a single new document. These files have their own header and footer settings and also have their own page numbers that must be persevered. However, when it currently inserts a new document, the page numbers and header/footer settings are continuous from the last document. In this example, I am simply putting together two documents, but I will eventually be stringing together 15-20 documents at a time. I know there is a way to maintain each document's original properties, but I can't seem to figure it out. Any suggestions from the experts would be very greatly appreciated! Thank you!
I am working on a macro that will string a series of files together in a single new document. These files have their own header and footer settings and also have their own page numbers that must be persevered. However, when it currently inserts a new document, the page numbers and header/footer settings are continuous from the last document. In this example, I am simply putting together two documents, but I will eventually be stringing together 15-20 documents at a time. I know there is a way to maintain each document's original properties, but I can't seem to figure it out. Any suggestions from the experts would be very greatly appreciated! Thank you!
Code:
Public Sub MAIN()
Dim wdApp As Word.Application, wdDoc As Word.Document
Dim wip, year, path, Filename, fullname, noextension
Dim sectionNum As Long
Set wdApp = GetObject(, "Word.Application")
If Err.Number <> 0 Then 'Word isn't already running
Set wdApp = CreateObject("Word.Application")
End If
Set wdDoc = wdApp.Documents.Open("C:\Doc1.doc")
'Create the file
ActiveDocument.SaveAs ("C:\NewDoc.doc")
'Go to the end of the document
Selection.EndKey Unit:=wdStory
Selection.InsertBreak Type:=wdSectionBreakOddPage
sectionNum = ActiveDocument.Sections.count
'Get current page header and set linktoprevious = false
Dim r As Range
Dim oSection As Section
Dim hfType
'Set r = ActiveDocument.Sections(sectionNum).Headers
Set oSection = ActiveDocument.Sections(sectionNum)
With oSection
For hfType = 1 To 3
'oSection.Headers(var).LinkToPrevious = False
Set r = oSection.Headers(var).Range
r.Delete
Next
End With
' Set r = ActiveDocument.Sections(sectionNum).Headers(hfType).Range
' r.Delete
' with r
' .Headers(hfType).LinkToPrevious = False
' .Footers(hfType).LinkToPrevious = False
' end with
'Insert next document
Selection.InsertFile ("C:\Doc2.doc")
'etc...
End Sub