View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
ryguy7272 ryguy7272 is offline
external usenet poster
 
Posts: 2,836
Default Import Excel 2003 data into Word 2003

Take a look at this:
http://word.mvps.org/FAQs/InterDev/C...WordFromXL.htm

This too:
http://addbalance.com/usersguide/fields.htm

And this:
http://gregmaxey.mvps.org/Word_Fields.htm

Finally, once you get the DocVariable fields set up in Word (hit Alt + F9 to
see all fields), run this code from Excel.
Sub PushToWord()

Dim objWord As New Word.Application
Dim doc As Word.Document
Dim bkmk As Word.Bookmark
sWdFileName = Application.GetOpenFilename(, , , , False)
Set doc = objWord.Documents.Open(sWdFileName)

With doc
..Variables("VarNumber1").Value = Range("VarNumber1").Value
..Variables("VarNumber2").Value = Range("VarNumber2").Value
'etc
..Range.Fields.Update
End With

'ActiveDocument.Fields.Update

objWord.Visible = True

End Sub

Note: This code runs in Excel; pushes Excel variables (assigned as Named
Ranges) to Word.

HTH,
Ryan---

--
Ryan---
If this information was helpful, please indicate this by clicking ''Yes''.


"statum" wrote:

Hello all, I am trying to write a macro in a Word 2003 document that will
allow the user to import some data from an Excel 2003 spreadsheet. I got
started with trying to "MailMerge" using the code below but all it does is
open a BLANK, new word document and it does not import anything from the
Excel sheet. Any ideas? Is MailMerge the wrong direction to go with this?
Thanks in advace for the help.

Sub ImportDatafromExcelintoWord()

Dim docNew As Document

Set docNew = Documents.Add

With docNew.MailMerge
.MainDocumentType = wdNotAMergeDocument
.OpenDataSource Name:="C:\Data\ExcelImportData.xls", _
ReadOnly:=True, _
Connection:="CustomerData"

End With
End Sub