
Excel export & create Word document
Hi Sam,
Well, in that case what *I* would do is insert a LINK field
into the Word document that contains the necessary worksheet
path and (named) range information. Rather than rely on
copy/paste over a VBA interface.
To see what I'm talking about: Copy a table in Excel, switch
to Word, and use Edit/Paste Special with a Link. Now press
Alt+F9 to display the field codes (this is like looking at
info in Excel's formula bar). You should see something like
this:
{ LINK Excel.Sheet.8 "E:\\My Documents\\MergData.xls"
"TestLinkedData!LinkData" \a \h }
So, what you need to pass from Excel is the path (with
doubled backslashes) and the worksheet!range.
For information on how you start up Word from within Excel,
see the mvps.org/word website. Once you have a document
opened or created, you do something like this:
ActiveDocument.Fields.Add _
Range:=Selection.Range
Type:=wdFieldLink
Text:= "Excel.Sheet.8 " & """" & _
"E:\\My Documents\\MergData.xls" & _
"""" & " " & """" & _
"TestLinkedData!LinkData" & """" & " \a \h"
PreserveFormatting:=True
Quote:
> I am currently working with Excel VBA and wish to export a
> particular range of data to create a new word document and
> have this pasted into it thus creating a table.
> I am using Office 2000 on Windows 2000
Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister
http://www.mvps.org/word
http://go.compuserve.com/MSOfficeForum
This reply is posted in the Newsgroup; please post any follow
question or reply in the newsgroup and not by e-mail :-)