Get a cell value from excel

C

cag

Hi,

Firs of all, thank you for reeding my question. I would like to get a cell
value from a excel file into a word file, using macros programming. I mean,
developing a macro able to read a cell.

Thanks
 
H

Helmut Weber

Hi,

Just the principle:

Sub Test444()
'reference to word library
Dim oWrd As Word.Application
Dim oDoc As Word.Document
Set oWrd = CreateObject("word.application")
Set oDoc = oWrd.Documents.Open("c:\test\testdoc.doc")
' oWrd.Visible = False
oDoc.Tables(2).Cell(3, 3).Range.Text = _
ActiveWorkbook.Worksheets(1).Cells(3, 3).Value
oDoc.Save
oDoc.Close
Set oDoc = Nothing
oWrd.Quit
Set oWrd = Nothing
End Sub

Greetings from Bavaria, Germany

Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
 
H

Helmut Weber

Oops,

the example started from Excel.

For a start from Word it would be,
if there is no instance of Excel already active.


Sub Test444()
'reference to Excel library required
Dim oExc As Excel.Application
Dim oWrk As Excel.Workbook
Set oExc = CreateObject("Excel.application")
Set oWrk = oExc.Workbooks.Open("c:\test\Excelfile.xls")
' oWrd.Visible = False
ActiveDocument.Tables(1).Cell(1, 1).Range.Text = _
oWrk.Worksheets(1).Cells(1, 1).Value
oWrk.Close
Set oWrk = Nothing
oExc.Quit
Set oExc = Nothing
End Sub

Greetings from Bavaria, Germany

Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
 

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