I am interested in pulling values from Excel into Word to automate reports. I have in the past used the GetObject function successfully and really liked the functionality. Recently our company upgraded to Office 2007 and when this happened I have not been able to get the same macros to work. I bought a book called Mastering VBA for Office 2007 and am using an Example out of the book. The code for the example reads:
Sub Return_a_Value_from_Excel()
Dim mySpreadsheet As Excel.Workbook
Dim StrSalesTotal As String
Set mySpreasheet = GetObject("C:\Book1.xlsm")
strSalesTotal = mySpreasheet.Application.Range("SalesTotal").Value
Set mySpreadsheet = Nothing
Selection.TypeText "Current sales total: $" & strSalesTotal & "."
Selection.TypeParagraph
End Sub
I have a file on my computer "C:\Book1.xlsm" with a range defined and a value of 4 in that range. When I run the code I get the following error
Run-time error '1004':
Method "Range' of object '_Application' failed
Any help is a bonus!
Sub Return_a_Value_from_Excel()
Dim mySpreadsheet As Excel.Workbook
Dim StrSalesTotal As String
Set mySpreasheet = GetObject("C:\Book1.xlsm")
strSalesTotal = mySpreasheet.Application.Range("SalesTotal").Value
Set mySpreadsheet = Nothing
Selection.TypeText "Current sales total: $" & strSalesTotal & "."
Selection.TypeParagraph
End Sub
I have a file on my computer "C:\Book1.xlsm" with a range defined and a value of 4 in that range. When I run the code I get the following error
Run-time error '1004':
Method "Range' of object '_Application' failed
Any help is a bonus!