Import Excel 2003 data into Word 2003

S

statum

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
 
R

ryguy7272

Take a look at this:
http://word.mvps.org/FAQs/InterDev/ControlWordFromXL.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---
 

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