Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #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
  #2  
Old 03-09-2021, 05:03 PM
macropod's Avatar
macropod macropod is offline Merging Word documents Windows 10 Merging Word documents Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #3  
Old 03-10-2021, 09:23 AM
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
Default 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.
Reply With Quote
  #4  
Old 03-10-2021, 09:40 AM
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
Smile 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.
Reply With Quote
  #5  
Old 03-10-2021, 02:49 PM
macropod's Avatar
macropod macropod is offline Merging Word documents Windows 10 Merging Word documents Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by kp4bnx View Post
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 code saves the updates in the document it is run from as well as producing a PDF.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



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 07:44 PM.


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