Whoa! Looks like this is your first post ever, and you're posting in the
Excel Functions area, when you should really be posting this question in the
Excel Programming area. Oh well, I'll tell you how to do what you want to
do, but I feel it may take a little effort on your part to grasp everything.
How to send data from Excel to Word (using Fields):
In Word, click Insert > Field > DocVariable, then name your DocVariable.
Repeat as many times as necessary. In this example, I am using
‘BrokerFirstName’ and ‘BrokerLastName’. Basically, I’m doing some analytics
in Excel, and preparing the results, in the form of a letter, to a
StockBroker, including the broker’s first and last name and as many other
variables as necessary.
In Excel, hit Alt+F11, click Tools > References > check the reference for
Microsoft Word
xx.x Object Library. Then copy/paste this code into Excel’s Visual Basic
Editor window:
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)
'On Error Resume Next
objWord.ActiveDocument.variables("BrokerFirstName").Value =
Range("BrokerFirstName").Value
objWord.ActiveDocument.variables("BrokerLastName").Value =
Range("BrokerLastName").Value
objWord.ActiveDocument.Fields.Update
'On Error Resume Next
objWord.Visible = True
End Sub
A few more examples for you...
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--