Merge many Word documents using a Excel macro

A

AP

I have created a macro that uses an Excel spreadsheet to merge many
Excel files together. The spreadsheet has file name and location
information. I want to do the same for many Word documants. Currently
I have a Word macro that simply creates a new word document then just
adds and formats all the required documents.

What I want to do is add another tab on the Excel spreadsheet and have
all of the file name and location information for the Word documents
there and have Excel create the Word document. I have taken some code
from another post and it seems to almost work...

Dim wrdAPPnew As Word.Application
Dim wrdDOCnew As Word.Document

Set wrdAPPnew = CreateObject("Word.Application")
wrdAPPnew.Visible = True

With wrdDOCnew
 
H

haroldk

You could use something like this:
Sub foo()
Dim wrdAPPnew As Word.Application
Dim wrdDOCnew As Word.Document
Dim currentInsertFileName(3) As String
Dim x As Integer
currentInsertFileName(0) = "c:\test\doc0.doc"
currentInsertFileName(1) = "c:\test\doc1.doc"
currentInsertFileName(2) = "c:\test\doc2.doc"
Set wrdAPPnew = CreateObject("Word.Application")
wrdAPPnew.Visible = True
Set wrdDOCnew = wrdAPPnew.Documents.Add
With wrdAPPnew
For x = 0 To 2
With .Selection
.InsertFile Filename:=currentInsertFileName(x), Range:=""
.EndKey wdStory
.InsertBreak (wdSectionBreakNextPage)
End With
Next
End With
Set wrdDOCnew = Nothing
Set wrdAPPnew = Nothing
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top