Insert values from Excel at Bookmarks in Word

R

Raj

Hi,

I have a word document (Document1) with five bookmarks. I have an
excel workbook (Workbook1) with three sheets. I want to insert values
from different cells in the excel workbook into the five bookmarks.
The values in the excel workbook are placed in different cells in the
three worksheets. What would the be the code to accomplish this?

I assume the mail-merge option is out because it requires a list. The
data here is scattered across the different worksheets.

Thanks in advance for the help.

Regards,
Raj
 
S

StevenM

To: Raj,

The basic idea is as follows:

'
' With the VBA editor at: Tools > Reference
' add: Microsoft Excel Object Library item
'
Sub ReturnValueFromExcel()
Dim oXL As Excel.Workbook
Dim sFileName As String
Dim sValue As String
Dim sBookmark As String

sFileName = "C:\Documents and Settings\Steven\Desktop\Book1.xls"
sBookmark = "ThisBookmark"

If Dir(sFileName) > "" Then
Set oXL = GetObject(sFileName)
sValue = CStr(oXL.Application.Range("A2").value)
End If
If ActiveDocument.Bookmarks.Exists(sBookmark) = True Then
ActiveDocument.Bookmarks(sBookmark).Range.Text = sValue
End If
End Sub

Steven Craig Miller
 

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