VBA & Excel: "Object required" error

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello All:
I would like to read an excel file from Autocad and use some values in my VBA program. But I have a problem and I don't manage to solve it on my own even though I did a lot of research.
If you look at my code below, the GetCellValue function does not work: I have the run time error 424 "object required". I do not understand this error because ExcelConnect works and finds my excel file.
Could you please help me? Any help would be greatly appreciated.
Thanks,
Here is my code:
Option Explicit
Dim excelapp As Object
Dim mspace As AcadModelSpace
Function ExcelConnect()
' This function connects excel with autocad
'On Error Resume Next
Set excelapp = GetObject("C:\Program Files\AutoCAD ART Prototype\Application.xls")
If Err Then
Err.Clear
Set excelapp = CreateObject("Excel.Application")
excelapp.Visible = True
If Err Then
MsgBox Err.Description
Exit Function
End If
End If
MsgBox "Now running " & excelapp.Name
End Function
Function ExcelClose() ' This function closes the connection between excel and Autocad
Set excelapp = Nothing
End Function
Function GetCellValue(row As Integer, column As Integer) As Double
' This function returns the value of a given cell in excel.
GetCellValue = excelapp.activesheet.Cells(row, column).value
End Function
Sub ExcelToAcad()
Dim LTP_Origin_dist_262 As Double
Dim LTP_Origin_dist_136 As Double
Dim slope As Double
ExcelConnect
LTP_Origin_dist_262 = GetCellValue(14, 13)
LTP_Origin_dist_136 = GetCellValue(15, 13)
slope = GetCellValue(16, 13)
' Closing the excel-autocad link
ExcelClose
End Sub