Pages in topic:   [1 2] >
Ms Word macro to merge all documents in a folder (recursive)
Thread poster: Hans Lenting
Hans Lenting
Hans Lenting
Netherlands
Member (2006)
German to Dutch
Mar 8, 2023

Somewhere at this website I have found this great macro that merges all documents in a folder, including those in any subfolders, while keeping the layout!

While this macro works on Windows, it doesn't work on macOS, because of the missing FSO object.

Is anyone able to remove that part and to 'hard
... See more
Somewhere at this website I have found this great macro that merges all documents in a folder, including those in any subfolders, while keeping the layout!

While this macro works on Windows, it doesn't work on macOS, because of the missing FSO object.

Is anyone able to remove that part and to 'hard code' one import folder 'to_merge' on the Desktop (either the Windows one or the macOS one)? No scanning of subfolders needed.

That would be very nice!
Collapse


 
Dan Lucas
Dan Lucas  Identity Verified
United Kingdom
Local time: 21:35
Member (2014)
Japanese to English
FSO Mar 8, 2023

Hans Lenting wrote:
Is anyone able to remove that part and to 'hard code' one import folder 'to_merge' on the Desktop (either the Windows one or the macOS one)? No scanning of subfolders needed.

Short answer is "not me", but the instructions on alternative calls for avoiding the FSO on a Mac in this link look quite complete. Might turn out to be quite fiddly though.

Regards,
Dan


 
Hans Lenting
Hans Lenting
Netherlands
Member (2006)
German to Dutch
TOPIC STARTER
Thank you Mar 8, 2023

Dan Lucas wrote:

... the instructions on alternative calls for avoiding the FSO on a Mac in this link look quite complete. Might turn out to be quite fiddly though.

Regards,
Dan


Thank you very much. Will have a look at it.


 
Tony M
Tony M
France
Local time: 22:35
Member
French to English
+ ...
SITE LOCALIZER
Cheap utility Mar 8, 2023

I did once find a very handy little utility that was quite inexpensive that would join Word files — and even more usefully, split them again later!
The only snag I found was its inability when splitting them to restore the original filenames. My workaround was to pre-process each file using a simple macro to insert the filename into (e.g.) the headers, so it would be at least visible after joining / splitting.


Hans Lenting
 
Stepan Konev
Stepan Konev  Identity Verified
Russian Federation
Local time: 23:35
English to Russian
Name? Mar 8, 2023

Tony M wrote:
I did once find a very handy little utility
Can you name it or give a link?
When I need to merge a bunch of files, I use MS Word command (Insert > Object > Text from file > select all files except the opened one). However you can't split them back, so a utility would be very useful.


 
Tony M
Tony M
France
Local time: 22:35
Member
French to English
+ ...
SITE LOCALIZER
Google it Mar 8, 2023

Stepan Konev wrote:

Can you name it or give a link?


Sorry, no... but the name was very self-explanatory, and I found it easily just be doing an Internet search. I think it was called something like MS Join/Split.
But I don't know if it's still available, but there used to be several different ones around.


 
Hans Lenting
Hans Lenting
Netherlands
Member (2006)
German to Dutch
TOPIC STARTER
Loss Mar 8, 2023

Stepan Konev wrote:

When I need to merge a bunch of files, I use MS Word command (Insert > Object > Text from file > select all files except the opened one).


A lot of formatting and info will be lost.


 
Stepan Konev
Stepan Konev  Identity Verified
Russian Federation
Local time: 23:35
English to Russian
Not sure what you mean Mar 8, 2023

Hans Lenting wrote:
A lot of formatting and info will be lost.
When I merge files with that feature, all formatting and headers/footers remain exactly as they are in original files.
Update: Ok, probably this is because I never used it for any purpose other than word counting.


[Edited at 2023-03-08 19:47 GMT]


Hans Lenting
 
Hans Lenting
Hans Lenting
Netherlands
Member (2006)
German to Dutch
TOPIC STARTER
Answer Mar 8, 2023

Stepan Konev wrote:
When I merge files with that feature, all formatting and headers/footers remain exactly as they are in original files.
Update: Ok, probably this is because I never used it for any purpose other than word counting.


I see. I want an exact copy of all subdocuments combined.

Inserting via Text from file loses the page orientation and headers. The macro for Windows works fine ... but for Windows only.

Subdocument:
1

Inserted via your method:
2

Inserted via the macro:
3
Page orientation and headers are preserved.


[Edited at 2023-03-08 21:00 GMT]


Stepan Konev
 
Michael Beijer
Michael Beijer  Identity Verified
United Kingdom
Local time: 21:35
Member (2009)
Dutch to English
+ ...
Kutools for Word? Mar 8, 2023

I think Kutools for Word (from extendoffice.com) can do it. See: https://www.extendoffice.com/product/kutools-for-word/word-merge-documents.html

However, merging multiple Word docs (in order to create a single document for previewing in LibreOffice in CafeTran) is really something your CAT tool should do in the background...
See more
I think Kutools for Word (from extendoffice.com) can do it. See: https://www.extendoffice.com/product/kutools-for-word/word-merge-documents.html

However, merging multiple Word docs (in order to create a single document for previewing in LibreOffice in CafeTran) is really something your CAT tool should do in the background
Collapse


 
Michael Beijer
Michael Beijer  Identity Verified
United Kingdom
Local time: 21:35
Member (2009)
Dutch to English
+ ...
or use an online tool Mar 8, 2023

see e.g.: https://products.aspose.app/words/merger/doc

 
Hans Lenting
Hans Lenting
Netherlands
Member (2006)
German to Dutch
TOPIC STARTER
Nice Mar 8, 2023

Michael Beijer wrote:

I think Kutools for Word (from extendoffice.com) can do it. See: https://www.extendoffice.com/product/kutools-for-word/word-merge-documents.html

However, xxxxxx


Nice tool!


 
Hans Lenting
Hans Lenting
Netherlands
Member (2006)
German to Dutch
TOPIC STARTER
Failed Mar 8, 2023

Michael Beijer wrote:

see e.g.: https://products.aspose.app/words/merger/doc


Tried to merge 10 docx to pdf, downloaded one pdf with only 4 pages.


 
Hans Lenting
Hans Lenting
Netherlands
Member (2006)
German to Dutch
TOPIC STARTER
Doesn't work on Mac Mar 12, 2023

I have now created a version without any FSO stuff, but it still doesn't work on Word for Mac. I have posted a question in the appropriate Ms Forum.

 
Hans Lenting
Hans Lenting
Netherlands
Member (2006)
German to Dutch
TOPIC STARTER
Solved Mar 12, 2023

I have replaced two backslashes with forward slashes and the macro works in Word for Mac now.

There is still an issue with permissions: the merge folder and the subdocuments in that folder have to be granted access:

Screen Shot 2023-03-12 at 23.18.03

Hopefully this can be solved too.

Option Explicit
Dim wdDocTgt As Document, strTgt As String

Sub CombineDocuments()
Application.ScreenUpdating = False
Dim strFolder As String, StrFile As String
Dim wdDocSrc As Document, HdFt As HeaderFooter
Set wdDocTgt = ActiveDocument: strTgt = ActiveDocument.FullName
strFolder = "/Users/hl/Desktop/merge"

StrFile = Dir(strFolder & "/*.docx", vbNormal)
While StrFile ""
If strFolder & StrFile strTgt Then
Set wdDocSrc = Documents.Open(FileName:=strFolder & "/" & StrFile, AddToRecentFiles:=False, Visible:=False)
With wdDocTgt
.Characters.Last.InsertBefore vbCr
.Characters.Last.InsertBreak (wdSectionBreakNextPage)
With .Sections.Last
For Each HdFt In .Headers
With HdFt
.LinkToPrevious = False
.Range.Text = vbNullString
.PageNumbers.RestartNumberingAtSection = True
.PageNumbers.StartingNumber = wdDocSrc.Sections.First.Headers(HdFt.Index).PageNumbers.StartingNumber
End With
Next
For Each HdFt In .Footers
With HdFt
.LinkToPrevious = False
.Range.Text = vbNullString
.PageNumbers.RestartNumberingAtSection = True
.PageNumbers.StartingNumber = wdDocSrc.Sections.First.Headers(HdFt.Index).PageNumbers.StartingNumber
End With
Next
End With
Call LayoutTransfer(wdDocTgt, wdDocSrc)
.Range.Characters.Last.FormattedText = wdDocSrc.Range.FormattedText
With .Sections.Last
For Each HdFt In .Headers
With HdFt
.Range.FormattedText = wdDocSrc.Sections.Last.Headers(.Index).Range.FormattedText
.Range.Characters.Last.Delete
End With
Next
For Each HdFt In .Footers
With HdFt
.Range.FormattedText = wdDocSrc.Sections.Last.Footers(.Index).Range.FormattedText
.Range.Characters.Last.Delete
End With
Next
End With
End With
wdDocSrc.Close SaveChanges:=False
End If
StrFile = Dir()
Wend
Set wdDocSrc = Nothing
Application.ScreenUpdating = True
End Sub

Sub LayoutTransfer(wdDocTgt As Document, wdDocSrc As Document)
Dim sPageHght As Single, sPageWdth As Single
Dim sHeaderDist As Single, sFooterDist As Single
Dim sTMargin As Single, sBMargin As Single
Dim sLMargin As Single, sRMargin As Single
Dim sGutter As Single, sGutterPos As Single
Dim lPaperSize As Long, lGutterStyle As Long
Dim lMirrorMargins As Long, lVerticalAlignment As Long
Dim lScnStart As Long, lScnDir As Long
Dim lOddEvenHdFt As Long, lDiffFirstHdFt As Long
Dim bTwoPagesOnOne As Boolean, bBkFldPrnt As Boolean
Dim bBkFldPrnShts As Boolean, bBkFldRevPrnt As Boolean
Dim lOrientation As Long
With wdDocSrc.Sections.Last.PageSetup
lPaperSize = .PaperSize
lGutterStyle = .GutterStyle
lOrientation = .Orientation
lMirrorMargins = .MirrorMargins
lScnStart = .SectionStart
lScnDir = .SectionDirection
lOddEvenHdFt = .OddAndEvenPagesHeaderFooter
lDiffFirstHdFt = .DifferentFirstPageHeaderFooter
lVerticalAlignment = .VerticalAlignment
sPageHght = .PageHeight
sPageWdth = .PageWidth
sTMargin = .TopMargin
sBMargin = .BottomMargin
sLMargin = .LeftMargin
sRMargin = .RightMargin
sGutter = .Gutter
sGutterPos = .GutterPos
sHeaderDist = .HeaderDistance
sFooterDist = .FooterDistance
bTwoPagesOnOne = .TwoPagesOnOne
' bBkFldPrnt = .BookFoldPrinting
' bBkFldPrnShts = .BookFoldPrintingSheets
' bBkFldRevPrnt = .BookFoldRevPrinting
End With
With wdDocTgt.Sections.Last.PageSetup
.GutterStyle = lGutterStyle
.MirrorMargins = lMirrorMargins
.SectionStart = lScnStart
.SectionDirection = lScnDir
.OddAndEvenPagesHeaderFooter = lOddEvenHdFt
.DifferentFirstPageHeaderFooter = lDiffFirstHdFt
.VerticalAlignment = lVerticalAlignment
.PageHeight = sPageHght
.PageWidth = sPageWdth
.TopMargin = sTMargin
.BottomMargin = sBMargin
.LeftMargin = sLMargin
.RightMargin = sRMargin
.Gutter = sGutter
.GutterPos = sGutterPos
.HeaderDistance = sHeaderDist
.FooterDistance = sFooterDist
.TwoPagesOnOne = bTwoPagesOnOne
' .BookFoldPrinting = bBkFldPrnt
' .BookFoldPrintingSheets = bBkFldPrnShts
' .BookFoldRevPrinting = bBkFldRevPrnt
.PaperSize = lPaperSize
.Orientation = lOrientation
End With
End Sub


 
Pages in topic:   [1 2] >


To report site rules violations or get help, contact a site moderator:


You can also contact site staff by submitting a support request »

Ms Word macro to merge all documents in a folder (recursive)






TM-Town
Manage your TMs and Terms ... and boost your translation business

Are you ready for something fresh in the industry? TM-Town is a unique new site for you -- the freelance translator -- to store, manage and share translation memories (TMs) and glossaries...and potentially meet new clients on the basis of your prior work.

More info »
Wordfast Pro
Translation Memory Software for Any Platform

Exclusive discount for ProZ.com users! Save over 13% when purchasing Wordfast Pro through ProZ.com. Wordfast is the world's #1 provider of platform-independent Translation Memory software. Consistently ranked the most user-friendly and highest value

Buy now! »