GrandpaB
07-30-2007, 08:24 PM
I'm having trouble reading data from Excel into Word using the Cells method. I have been able to read data using Range. Here is my code:
Option Explicit
Public MyExcel As Excel.Workbook
Public XX As String
Private Sub Document_Open()
Dim Path As String
Path = "C:\My Documents\LDSInvoices\"
Set MyExcel = GetObject(Path & "LDSInvoices.xls")
' XX = MyExcel.Application.Cells(2, 2).value
' XX = MyExcel.Application.Range(.Cells(2, 2)).value
XX = MyExcel.Application.Range("B2").value
End Sub
The XX gets the value contained in the B2 cell of the spreadsheet, but unfortunately I need the Cells method to work so that I can itterate through the spreadsheet. I have commented out several of my failed attempts to solve this problem. I get a compile error - Method 'Cells' of object '_Application' failed.
Your help in my VBA education would be greatly appreciated, thanks.
Option Explicit
Public MyExcel As Excel.Workbook
Public XX As String
Private Sub Document_Open()
Dim Path As String
Path = "C:\My Documents\LDSInvoices\"
Set MyExcel = GetObject(Path & "LDSInvoices.xls")
' XX = MyExcel.Application.Cells(2, 2).value
' XX = MyExcel.Application.Range(.Cells(2, 2)).value
XX = MyExcel.Application.Range("B2").value
End Sub
The XX gets the value contained in the B2 cell of the spreadsheet, but unfortunately I need the Cells method to work so that I can itterate through the spreadsheet. I have commented out several of my failed attempts to solve this problem. I get a compile error - Method 'Cells' of object '_Application' failed.
Your help in my VBA education would be greatly appreciated, thanks.