Title says it. A tall order, I know. Is it even possible? Been trying a few convoluted methods and gotten close but not quite. One way that
almost works is using a macro to open each component file, add a section break at the end, store its margins, close it, and then use Selection.InsertFile to add it to the blob and reapply its margins. This kinda works except the header/footer content
and properties (alternation, etc.) persist from the prior document in the stack despite setting LinkToPrevious to False.
Obviously this is a major (maybe foolish?) exercise and I'm not done experimenting, but has anyone else attempted this in earnest & come out with any lessons (including
'forget it!')? And yes, I know the One True Answer is probably PDFing but I'm not actually the one who dreamed up this quest, the goal of which is to have a mega-document that's relatively easier to edit or comment than a PDF would be.
I do notice I get different results from setting the Link arg to True or False. Linking, which seems preferable to keep the file size down, blanks out all headers & footers
after the first doc regardless of other gyrations.
Code is below. Any clues appreciated.
Sub Test()
Dim fname As String, i As Long, FI() As String
Dim dx As Document, d As Document, newdoc As Document
Dim sek As Section, hf As HeaderFooter
Dim lm As Single, rm As Single, tm As Single, bm As Single
ReDim FI(50)
fname = Dir$("C:\Test\*.docx")
Do While fname <> "": i = i + 1: FI(i) = "C:\Test" & fname: fname = Dir$: Loop
ReDim Preserve FI(i)
For i = 1 To UBound(FI)
If i = 1 Then
Set newdoc = Documents.Open(FI(i))
Else
'store margin info
Set dx = Documents.Open(FI(i), Visible:=False)
lm = dx.Sections(1).PageSetup.LeftMargin
rm = dx.Sections(1).PageSetup.RightMargin
tm = dx.Sections(1).PageSetup.TopMargin
bm = dx.Sections(1).PageSetup.BottomMargin
dx.Close 0
'insert file at end
newdoc.Activate
Selection.EndKey wdStory
Selection.Paragraphs(1).Range.InsertFile FI(i), , , False
With Selection.Sections(1).PageSetup
.TopMargin = tm
.BottomMargin = bm
.LeftMargin = lm
.RightMargin = rm
End With
If i > 1 Then
For Each hf In Selection.Sections(1).Headers
hf.LinkToPrevious = False
DoEvents
Next
For Each hf In Selection.Sections(1).Footers
hf.LinkToPrevious = False
DoEvents
Next
End If
End If
Next i
End Sub