Importing information from excel to word

R

ryanadgriffith

Can anyone help me with a Macro, I have no experience in VBA at all.
I need a macro that will take a numerical value from a cell in excel
and put the vaule where ever I want it in word. Thanks for your help
 
P

Peter Jamieson

Depending on exactly what you need, you may not need a macro. Try...
a. in Excel, open the workbook, select the cell, then Edit|Copy
b. in Word, Edit|Paste Special and select "Paste Link". Then select one of
the options such as Plain text.

A { LINK } field is inserted into the Word document. The result of the LINK
field should be the value in the cell. If you modify the cell content, then
update the LINK field (e.g. by selecting it and pressing F9) the field
result should be updated. You should be able to put such a field most places
in a Word document (although there may be exceptions).

Peter Jamieson
 
R

ryanadgriffith

Depending on exactly what you need, you may not need a macro. Try...
a. in Excel, open the workbook, select the cell, then Edit|Copy
b. in Word, Edit|Paste Special and select "Paste Link". Then select one of
the options such as Plain text.

A { LINK } field is inserted into the Word document. The result of the LINK
field should be the value in the cell. If you modify the cell content, then
update the LINK field (e.g. by selecting it and pressing F9) the field
result should be updated. You should be able to put such a field most places
in a Word document (although there may be exceptions).






- Show quoted text -

Thanks for your reply, but I dont want to do it that way because I
dont want the values to change everytime I change my excel work sheet.
I want a macro so when I run it, it takes the values from excel and
puts them into word
 
P

Peter Jamieson

Well for that you would probably be better off looking in an Excel group for
a comprehensive macro that dealt with all situations (e.g whether or not the
sheet is closed, error handling etc.) but for example you could
a. set a reference to Microsoft Excel 11.0 Object Library (or whichever
version is appropriate)
b. use a function such as

Function getcellvalue(strWBPath As String, _
strWSname As String, _
lngRow As Long, _
lngColumn As Long)
Dim objExcel As Excel.Application
Dim objWB As Excel.Workbook
Dim objWS As Excel.Worksheet

Set objExcel = CreateObject("Excel.Application")
With objExcel
Set objWB = .Workbooks.Open(FileName:=strWBPath, ReadOnly:=True)
Set objWS = objWB.Worksheets(strWSname)
getcellvalue = objWS.Cells(lngRow, lngColumn).Value
Set objWS = Nothing
objWB.Close savechanges:=False
Set objWB = Nothing
End With
objExcel.Quit
Set objExcel = Nothing

End Function

c. call it using e.g.

msgbox getcellvalue("c:\myxlwbs\myxlwb.xls","mysheetname",23,3)

to get the value of row 23 column C

Peter Jamieson
 

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