Extract data from Excel and use it in AutoCAD

Submitted by techrev on Wed, 09/13/2017 - 11:54
autocad vba automation

You can extract the data from an excel file (without opening it) and use it inside an AutoCAD file for drawing objects;

This is just an example on How to use the data from Excel Cells inside the CAD drawing to Automate the Autocad drawing process.

autocad vba automation

Don't forget to add Microsoft Excel Object Libraries (Tools->References) [AutoCAD VBA Editor]

Steps

  1. Go to VBA Editor and insert a module (Module1)
  2. Paste following code inside (see the bottom)
  3. Save the macro as datafromexcel.dvb (or any other name you prefer with *.dvb extension)
  4. save the drawing file
  5. create an Excel file (in your D drive) and enter some text/number inside cell (A:1) then save it and close.
  6. Insert a toolbar and a button inside CAD file  (refer previous articles)
  7. link vba with button using the code ^C^C_-vbarun;Module1.clicked
  8. Set up the autoload

Done !

When you click on your button, you can see the message box with the value in Cell A:1

Public Sub clicked()
Dim test As String
Dim objExcel As New Excel.Application
Dim exWb As Excel.Workbook
Set exWb = objExcel.Workbooks.Open("d:\dataforautocad.xls")
test = exWb.Sheets("Client").Cells(1, 1) 'R,C format
exWb.Close
Set exWb = Nothing
MsgBox test

End Sub

 

AUTOCAD VBA AUTOMATION

AUTOCAD AND EXCEL AUTOMATION

COMPUTER AIDED AUTOMATION