#1
|
|||
|
|||
Merging Word documents
I inherited a macro at work that combined 16 word documents into one document at my office. Each document has a unique header. Prior to Office 365, this worked fine. Since the upgrade, the headers are no longer unique. The header of the first document is now on all subsequent documents. Below is the code, which I shortened to show just 3 documents being merged, as my original code merges 16 documents. Additionally, it doesn't make any difference if I alter the code for the "docx" format or use the "doc" format. I can somewhat understand what the code does, but I struggle trying to write code. Can anyone please offer some insight on how I can fix this problem? Thanks.
Code:
Sub MergeDocs() ' Documents.AddDocumentType:=wdNewBlankDocument IfSelection.PageSetup.Orientation = wdOrientPortrait Then Selection.PageSetup.Orientation = wdOrientLandscape Else Selection.PageSetup.Orientation = wdOrientPortrait End If With Selection.PageSetup .LineNumbering.Active =False .Orientation =wdOrientLandscape .TopMargin =InchesToPoints(0.25) .BottomMargin = InchesToPoints(0.25) .LeftMargin =InchesToPoints(0.25) .RightMargin =InchesToPoints(0.2) .Gutter =InchesToPoints(0) .HeaderDistance =InchesToPoints(0.5) .FooterDistance =InchesToPoints(0.5) .PageWidth =InchesToPoints(11) .PageHeight =InchesToPoints(8.5) .FirstPageTray =wdPrinterDefaultBin .OtherPagesTray =wdPrinterDefaultBin .SectionStart =wdSectionNewPage .OddAndEvenPagesHeaderFooter = False .DifferentFirstPageHeaderFooter = False .VerticalAlignment =wdAlignVerticalTop .SuppressEndnotes = False .MirrorMargins = False .TwoPagesOnOne = False .BookFoldPrinting = False .BookFoldRevPrinting =False .BookFoldPrintingSheets =1 .GutterPos =wdGutterPosLeft End With ChangeFileOpenDirectory"C:\Document\Files" Selection.InsertFileFileName:= _ "C:\Document\Files\1Percent.docx", Range:="", _ ConfirmConversions:=False,Link:=False, Attachment:=False Selection.InsertBreakType:=wdPageBreak ChangeFileOpenDirectory"C:\Document\Files" Selection.InsertFileFileName:= _ "C:\Document\Files\2SPLY.docx", Range:="", _ ConfirmConversions:=False,Link:=False, Attachment:=False Selection.InsertBreakType:=wdPageBreak ChangeFileOpenDirectory"C:\Document\Files" Selection.InsertFileFileName:= _ "C:\Document\Files\3Variance.docx", Range:="", _ ConfirmConversions:=False,Link:=False, Attachment:=False Selection.InsertBreakType:=wdPageBreak Selection.HomeKeyUnit:=wdStory ActiveDocument.SaveAs2FileName:= _ "C:\Document\Report\FinalReport.docx", FileFormat:= _ wdFormatDocument,LockComments:=False, Password:="", AddToRecentFiles:= _ True,WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:= _ False,SaveNativePictureFormat:=False, SaveFormsData:=False, _ SaveAsAOCELetter:=False,CompatibilityMode:=0 End Sub |
#2
|
||||
|
||||
Did you look in the Combine Multiple Word Documents 'Sticky' thread at the top of this forum?
PS: When posting code, please use the code tags, indicated by the # button on the posting menu. Without them, your code loses much of whatever structure it had.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
Merging Word Documents
Hi, Yes I do see the thread posted at the top of the forum. I have tried it several times to no avail. I can see it cycling through my documents, then I see a message "Word is publishing document" but no final result is produced and the blank document I started with just disappears. I'm left with the spinning hamster wheel.
|
#4
|
|||
|
|||
Merging Word Documents
Ah...I see, it produced a PDF. I was staying within Word going back to the folder and didn't see it the additional file. The VBA does the trick...thanks for your prompt response.
|
#5
|
||||
|
||||
The code saves the updates in the document it is run from as well as producing a PDF.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Batch merging of Word documents | Harry Gateaux | Word VBA | 6 | 11-19-2020 09:58 AM |
Updating links while merging Word documents | ndw | Word VBA | 1 | 11-10-2017 01:07 PM |
Merging data from Two word documents based on number search | PRA007 | Word Tables | 6 | 11-23-2015 05:30 AM |
Merging bibliographies with word documents using separate master lists | Cimballi | Word | 3 | 07-01-2014 03:45 AM |
How to preserve or Retain bookmarks during Merging of word documents | ramsgarla | Word | 2 | 09-18-2012 08:59 AM |