excell auto-populate word?

L

LUCHA

I am attempting to make a “Word Document†which has some blanks
auto-populated from an “Excel Workbookâ€.

It would be best to create a “Word Document†to a sheet of an excel
workbook.
Am I on the right track?
How do I populate the blanks?
 
R

ryguy7272

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

Geoff_L

If you are using 07 then the process of linking is relatively simple.

Highlight the cells in Excel that you want to connect to Word and press
cntrl + C, to activate the copy function.

Go to the place in Word where you want this to appear and then click the
drop down menu below the Paste icon on the Home ribbon. Choose Paste Special.

You will now be presented with a Paste Special dialog box. Choose the Paste
Link option on the left hand side and then select the type of link that you
want to create. You will need to experiment with the formatting in both the
Excel document and the Word document as there are some issues here.

If this is helpful, please click Yes.
 

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

Similar Threads


Top