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
.
.
.

Selection.InsertFile Filename:=currentInsertFileName, Range:="",
_
ConfirmConversions:=False, Link:=False, Attachment:=False
.
.
.

End With

The "Selection.InsertFile..." command works fine while inside Word but
not from within Excel even though I have referenced the "Microsoft
Word 10.0 Object Library". When run I get a Run-time error 438, object
doesn't support this property or method.

Any ideas are appreciated

Alan Parekh

Re: Merge many Word documents using a Excel macro by haroldk

haroldk
Sun Aug 08 00:15:58 CDT 2004

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

--
Harold Kless, MCSD
Support Professional
Microsoft Technical Support for Business Applications
haroldk@microsoft.com

--
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
"AP" <abbtech@yahoo.com> wrote in message
news:fd2a944a.0408070057.11913d61@posting.google.com...
> 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
> .
> .
> .
>
> Selection.InsertFile Filename:=currentInsertFileName, Range:="",
> _
> ConfirmConversions:=False, Link:=False, Attachment:=False
> .
> .
> .
>
> End With
>
> The "Selection.InsertFile..." command works fine while inside Word but
> not from within Excel even though I have referenced the "Microsoft
> Word 10.0 Object Library". When run I get a Run-time error 438, object
> doesn't support this property or method.
>
> Any ideas are appreciated
>
> Alan Parekh