Mail Merge Object Value

G

Guest

Hi there,

I have a word template that retrieve a project value using our software.
However, within the word document I have an excel document. The excel
document within the word document should do some calculations based on the
project value in the word template.

I do have the value in the word document but need to know how to get the
value in the excel spreadsheet within the word document. Please note that the
project value is a mail merge object.

my question to you is:
how do i get the value from the microsoft word file in the excel spreadsheet
cell A2.

Thanks
 
G

Guest

You will need a macro in your WORD document along these lines:

Sub Write_To_Excel()

On Error Resume Next

Set MySpreadsheet = GetObject(, "Excel.Application")
If Err Then
Set MySpreadsheet = CreateObject("Excel.Application")
End If

' INPATH is directory path
' XLSNAME is w/book name


inpath = "C:\Documents and Settings\John\Desktop\"
xlsname = "MM.xls"
wordvalue = "From Word to A2"

wbook = inpath & "\" & xlsname

Set MySpreadsheet = GetObject(wbook)

With MySpreadsheet
.Application.Visible = True
.Parent.Windows(xlsname).Visible = True
.Application.Worksheets(Worksheet_name).Activate
.Application.Cells(2, 1).Value = wordvalue ' Get value from A2
End With

End Sub

HTH
 
G

Guest

Thanks Toppers!

I pass through the word at the moment, will start cracking on to get the
value in!
 

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