Sunday, November 27, 2011

Merging Document

Ever stuck in document merging challenge? I had done it plenty of time, without exception its not a very pleasing experience. One of similar event happen few days back when i have to combine the solution from many different vendor for a large tender.

Word 2010 hung and restart everytime i copy and pasted one document content to others, i tried a lot but of no use. Then I decided to automate it as much as i can. I tried to find out ready made tool but without success. After googling a bit i find a very simple Macro. All you need is to copy all your document in one folder,input the source folder location and bump, all of sudden you will get a single merged document.Off course it will not make it ready to use but still make the boring process a lot easier and save lot of time.

Sub test()
' test Macro
Dim rng As Range
Dim MainDoc As Document
Dim strFile As String
Const strFolder = "D:\SandBox\" 'make it as per your requirement

Set MainDoc = Documents.Add
strFile = Dir$(strFolder & "*.docx") ' can change to .doc
Do Until strFile = ""
Set rng = MainDoc.Range
rng.Collapse wdCollapseEnd
rng.InsertFile strFolder & strFile
strFile = Dir$()
End Sub

Thanks to .For complete instructions please visit Link

No comments: