Computer Aided Automation
AutoCAD VBA Sample code to get data from excel file - Printable Version

+- Computer Aided Automation (https://computeraidedautomation.com)
+-- Forum: CAA Discussions (https://computeraidedautomation.com/forum-7.html)
+--- Forum: VBA Programming (https://computeraidedautomation.com/forum-1.html)
+---- Forum: AutoCAD VBA (https://computeraidedautomation.com/forum-3.html)
+---- Thread: AutoCAD VBA Sample code to get data from excel file (/thread-6.html)



AutoCAD VBA Sample code to get data from excel file - techberth - 21-11-2019

Function getfromexcel()
Dim i As Integer
Dim j As Integer

Dim excelfil As String
excelfile = "D:\CAA DEMO\Excel Worksheet.xlsx"

Dim objExcel As New Excel.Application
Dim worksheetName As String
Dim exWb As Excel.Workbook
Set exWb = objExcel.Workbooks.Open(excelfile)
For i = 1 To 1000
If exWb.Sheets("Sheet1").Cells(i, 1) <> "" Then
i = i + 1
total = i
End If
Next

For i = 1 To total
A(i) = exWb.Sheets("Sheet1").Cells(i, 1)
B(i) = exWb.Sheets("Sheet1").Cells(i, 2)
Next
exWb.Close
Set exWb = Nothing
objExcel.Quit
End Function