?
Solved

Merging Word documents into a single document

Posted on 2013-11-11
6
Medium Priority
?
779 Views
Last Modified: 2014-01-06
THis question is a follow up question to http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Word/Q_28291498.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
0
Comment
Question by:tomfolinsbee
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 39642413
Perfectly feasible though the definition of quickly may be the issue however I suggest we get the previous question resolved before you take this one any further to avoid conflict

Chris
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 39650440
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.

'==========================================================================
'
' 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"

Open in new window


Chris
0
 
LVL 59

Accepted Solution

by:
Chris Bottomley earned 2000 total points
ID: 39650536
Improved answer, inherits the column settings from each document:

'==========================================================================
'
' VBScript Source File -- Created with SAPIEN Technologies PrimalScript 2009
'
' NAME: 
'
' Author:Chris Bottomley
' 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
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
		If startFlag Then
		    masterdoc.Bookmarks("\EndOfDoc").Range.InsertBreak wrdPageBreak
		Else
			Set masterDoc = wdApp.Documents.add(fil.path)
			startFlag = true
		End If
	    masterdoc.Bookmarks("\EndOfDoc").Range.InsertFile fil.path
    End If
Next
wdApp.visible = True
    WScript.Echo "Finished"

Open in new window


Chris
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:tomfolinsbee
ID: 39659152
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
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 39660070
The new document is opened but not saved so you need to save the new document before closing it

Chris
0
 

Author Closing Comment

by:tomfolinsbee
ID: 39759334
Apologies for the late reply, thanks for the Solution!
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This tutorial provides instructions on how to properly format your Word document using the inbuilt tools provided. The benefits of using these tools means your documents are more accessible and easily portable to other applications an…
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
The viewer will learn how to make their project stand out over others by learning how to change colors and shapes, add spaces, change directions, and add bullets to their charts.
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …
Suggested Courses

741 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question