Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
AutoCAD VBA Sample code to get data from excel file
#1
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
Reply
#1
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
Reply
CAA


Forum Jump:


Users browsing this thread: 1 Guest(s)