Páginas sobre el tema: [1 2] > |
Ms Word macro to merge all documents in a folder (recursive) Autor de la hebra: 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 Reino Unido Local time: 14:26 Miembro 2014 japonés al inglés
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 Países Bajos Miembro 2006 alemán al neerlandés PERSONA QUE INICIÓ LA HEBRA
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 Francia Local time: 15:26 Miembro francés al inglés + ... LOCALIZADOR DEL SITIO 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 Federación Rusa Local time: 16:26 inglés al ruso
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 Francia Local time: 15:26 Miembro francés al inglés + ... LOCALIZADOR DEL SITIO
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 Países Bajos Miembro 2006 alemán al neerlandés PERSONA QUE INICIÓ LA HEBRA
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 Federación Rusa Local time: 16:26 inglés al ruso 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 Países Bajos Miembro 2006 alemán al neerlandés PERSONA QUE INICIÓ LA HEBRA
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 Reino Unido Local time: 14:26 Miembro 2009 neerlandés al inglés + ... |
Michael Beijer Reino Unido Local time: 14:26 Miembro 2009 neerlandés al inglés + ... |
Hans Lenting Países Bajos Miembro 2006 alemán al neerlandés PERSONA QUE INICIÓ LA HEBRA
|
|
Hans Lenting Países Bajos Miembro 2006 alemán al neerlandés PERSONA QUE INICIÓ LA HEBRA
Tried to merge 10 docx to pdf, downloaded one pdf with only 4 pages. | | |
Hans Lenting Países Bajos Miembro 2006 alemán al neerlandés PERSONA QUE INICIÓ LA HEBRA 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 Países Bajos Miembro 2006 alemán al neerlandés PERSONA QUE INICIÓ LA HEBRA
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 | | |
Páginas sobre el tema: [1 2] > |