صفحات الموضوع: [1 2] > | Ms Word macro to merge all documents in a folder (recursive) ناشر الموضوع: 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 المملكة المتحدة Local time: 02:41 عضو (2014) ياباني إلى أنجليزي
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 هولندا عضو (2006) ألماني إلى هولندي بادئ الموضوع
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 فرنسا Local time: 03:41 عضو فرنسي إلى أنجليزي + ... مترجم الموقع 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 الاتحاد الروسي Local time: 04:41 أنجليزي إلى روسي
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 فرنسا Local time: 03:41 عضو فرنسي إلى أنجليزي + ... مترجم الموقع
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 هولندا عضو (2006) ألماني إلى هولندي بادئ الموضوع
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 الاتحاد الروسي Local time: 04:41 أنجليزي إلى روسي 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 هولندا عضو (2006) ألماني إلى هولندي بادئ الموضوع
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 المملكة المتحدة Local time: 02:41 عضو (2009) هولندي إلى أنجليزي + ... | Michael Beijer المملكة المتحدة Local time: 02:41 عضو (2009) هولندي إلى أنجليزي + ... | Hans Lenting هولندا عضو (2006) ألماني إلى هولندي بادئ الموضوع
|
|
Hans Lenting هولندا عضو (2006) ألماني إلى هولندي بادئ الموضوع
Tried to merge 10 docx to pdf, downloaded one pdf with only 4 pages. | | | Hans Lenting هولندا عضو (2006) ألماني إلى هولندي بادئ الموضوع 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 هولندا عضو (2006) ألماني إلى هولندي بادئ الموضوع
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 | | | صفحات الموضوع: [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) 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! » |
| Trados Studio 2022 Freelance | The leading translation software used by over 270,000 translators.
Designed with your feedback in mind, Trados Studio 2022 delivers an unrivalled, powerful desktop
and cloud solution, empowering you to work in the most efficient and cost-effective way.
More info » |
|
| | | | X Sign in to your ProZ.com account... | | | | | |