tomfolinsbee
asked on
Merging Word documents into a single document
THis question is a follow up question to https://www.experts-exchange.com/questions/28291498/MS-Word-macro-to-switch-columns-in-all-tables-in-all-documents-in-folder.html
How can I quickly merge all the Word documents in a folder into a single document, and add a page break between songs? I would like the songs added in alphabetical order as well.
Thanks!
Lantau-Songbook.zip
How can I quickly merge all the Word documents in a folder into a single document, and add a page break between songs? I would like the songs added in alphabetical order as well.
Thanks!
Lantau-Songbook.zip
Noting the previous question request to keep column widths this is not as easy as i thought it would be ... do you still want the individual files to keep thei column widths ... because on my first pass some of the data is lost to the right of the document.
Chris
'==========================================================================
'
' VBScript Source File -- Created with SAPIEN Technologies PrimalScript 2009
'
' NAME:
'
' AUTHOR: Jaguar Land Rover , Jaguar Land Rover
' DATE : 15/11/2013
'
' COMMENT:
'
'==========================================================================
Dim wdApp
Dim strErr
Dim tbl
Dim doc
Dim startFlag
On Error Resume Next
Set fso = CreateObject("Scripting.FileSystemObject")
Set folder = fso.GetFolder("C:\DeleteMe\Test1")
Set Files = folder.Files
Set wdApp = CreateObject("Word.application")
wdApp.visible = false
Set masterDoc = wdApp.Documents.add
startFlag = false
wrdPageBreak = 7
wrdCollapseEnd = 0
For Each fil In Files
If Right(LCase(fil), 5) = ".docx" OR Right(LCase(fil), 5) = ".docm" OR Right(LCase(fil), 4) = ".doc" Then
Set doc = wdApp.Documents.Open(fil.Path)
Set RNG = masterdoc.Range
RNG.Collapse wrdCollapseEnd
If startFlag Then
RNG.InsertBreak wrdPageBreak
Else
startFlag = true
End If
RNG.InsertAfter doc.range.text
doc.close
End If
Next
wdApp.visible = True
WScript.Echo "Finished"
Chris
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Chris,
I saved the script in notepad, and saved it, but it didn't turn in a .vbs file. So I copied it to an existing .vbs file, saved it, and ran it. I got a "finished" message, but I couldn't find any merged document. Where's the destination folder? Assume its supposed to be the same as the one where the script is?
Cheers,
Tom
I saved the script in notepad, and saved it, but it didn't turn in a .vbs file. So I copied it to an existing .vbs file, saved it, and ran it. I got a "finished" message, but I couldn't find any merged document. Where's the destination folder? Assume its supposed to be the same as the one where the script is?
Cheers,
Tom
The new document is opened but not saved so you need to save the new document before closing it
Chris
Chris
ASKER
Apologies for the late reply, thanks for the Solution!
Chris