Pages in topic: [1 2] > | Ms Word macro to merge all documents in a folder (recursive) Thread poster: Hans Lenting
|
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 United Kingdom Local time: 03:30 Member (2014) Japanese to English
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 Netherlands Member (2006) German to Dutch TOPIC STARTER
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 France Local time: 04:30 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. | |
|
|
Stepan Konev Russian Federation Local time: 05:30 English to Russian
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 France Local time: 04:30 Member French to English + ... SITE LOCALIZER
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 Netherlands Member (2006) German to Dutch TOPIC STARTER
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 Russian Federation Local time: 05:30 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 Netherlands Member (2006) German to Dutch TOPIC STARTER
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: Inserted via your method: Inserted via the macro: Page orientation and headers are preserved.
[Edited at 2023-03-08 21:00 GMT] | | | Michael Beijer United Kingdom Local time: 03:30 Member (2009) Dutch to English + ... | Michael Beijer United Kingdom Local time: 03:30 Member (2009) Dutch to English + ... | Hans Lenting Netherlands Member (2006) German to Dutch TOPIC STARTER
|
|
Hans Lenting Netherlands Member (2006) German to Dutch TOPIC STARTER
Tried to merge 10 docx to pdf, downloaded one pdf with only 4 pages. | | | 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 Netherlands Member (2006) German to Dutch TOPIC STARTER
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: 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) Trados Business Manager Lite | Create customer quotes and invoices from within Trados Studio
Trados Business Manager Lite helps to simplify and speed up some of the daily tasks, such as invoicing and reporting, associated with running your freelance translation business.
More info » |
| Protemos translation business management system | Create your account in minutes, and start working! 3-month trial for agencies, and free for freelancers!
The system lets you keep client/vendor database, with contacts and rates, manage projects and assign jobs to vendors, issue invoices, track payments, store and manage project files, generate business reports on turnover profit per client/manager etc.
More info » |
|
| | | | X Sign in to your ProZ.com account... | | | | | |