For the first test you do next
Copy and add this code in AutoCAD VBAIDE (Alt+F11)
in the module
then execute it, but change before all settings and file name
within the code block
See if this code will return all values in AutoCAD command line after
Code:
Option Explicit
' Notes:
' 1. requires settings: Tools -> Options -> General tab -> Error trapping field -> check "Break on Unhandled errors"
' 2. requires reference to Microsoft Excel XX.0 Object Library
Function IsExcelRunning() As Boolean
Dim xlApp As Excel.Application
On Error Resume Next
Set xlApp = GetObject(, "Excel.Application")
IsExcelRunning = (Err.Number = 0)
Set xlApp = Nothing
Err.Clear
End Function
Sub ReadExcelRange()
' To read data from specific Excel range
Dim xlApp As Excel.Application
Dim blnIsOK As Boolean
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
blnIsOK = IsExcelRunning()
If blnIsOK Then
Set xlApp = GetObject(, "Excel.Application")
Else
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
xlApp.UserControl = True
End If
Dim xlFileName As String
' set full path of your Excel file here:
xlFileName = "C:\MyFolder\MyFile.xlsx"
xlApp.Application.ScreenUpdating = False
' open file for read
Set xlBook = xlApp.Workbooks.Open(xlFileName)
Set xlSheet = xlBook.Worksheets("Sheet1") ' desired sheet name , same if use xlBook.Worksheets(1)
xlSheet.Activate
Dim xlrange As Excel.Range
Set xlrange = xlSheet.Range("A1:F25")
xlrange.Select
Dim cols As Long
Dim rows As Long
cols = xlrange.Columns.Count
rows = xlrange.rows.Count
Dim rangeValue As Variant
rangeValue = xlrange.Value2
' clean up memory
xlBook.Close False
Set xlBook = Nothing
xlApp.Quit
Set xlApp = Nothing
DoEvents
' go to Autocad then
Dim i, j
For i = 1 To rows
For j = 1 To cols
' read cell data separatelly just for test
ThisDrawing.Utility.Prompt vbLf & CStr(rangeValue(i, j))
Next
Next
End Sub