PDA

View Full Version : Word VBA linking Excel Cells to Word Bookmarks



kmjones
05-14-2010, 12:28 PM
I'm attempting to link cells in an excel file into a word document. So the user would fill out the excel document with the necessary data and then could click a macro in word that would pull those numbers into a word "letter" so to speak in the appropriate locations.

I've found some help using bookmarks to mark the "places" for the excel data to go but I am having trouble with the code itself.

Here is what I've got so far:

Sub AutoFill()
Dim WB As Excel.Workbook
Set WB = GetObject("T:\Folder\File.xls")
Selection.GoTo What:=wdGoToBookmark, Name:="Title"
Selection.TypeText (WB.Sheets("Database").Range("C4"))
Set WB = Nothing
End Sub

I'm having issues with the GetObject among other things I'm sure....

Any help from more experienced users would be greatly, greatly appreciated.

Thank you very much!

Krissy

Tinbendr
05-14-2010, 08:13 PM
Start here (http://word.mvps.org/faqs/interdev/controlxlfromword.htm), then read this (http://word.mvps.org/faqs/macrosvba/InsertingTextAtBookmark.htm), then use...

Call UpdateBookmark "BookMarkName1", oSheet.Range("A1")
You don't say how many and whether a loop should be used. But this should keep you busy for a little while.

Good Luck!

fumei
05-17-2010, 11:34 AM
You may also want to look at:

http://vbaexpress.com/forum/showthread.php?t=31502