Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 03-09-2021, 01:53 PM
kp4bnx kp4bnx is offline Merging Word documents Windows 10 Merging Word documents Office 2019
Novice
Merging Word documents
 
Join Date: Mar 2021
Posts: 3
kp4bnx is on a distinguished road
Question 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

Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Merging Word documents Batch merging of Word documents Harry Gateaux Word VBA 6 11-19-2020 09:58 AM
Merging Word documents Updating links while merging Word documents ndw Word VBA 1 11-10-2017 01:07 PM
Merging Word documents Merging data from Two word documents based on number search PRA007 Word Tables 6 11-23-2015 05:30 AM
Merging Word documents 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

Other Forums: Access Forums

All times are GMT -7. The time now is 05:47 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft