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(, "Excel.Application")
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
End Function
Function ExcelClose()
' This function closes the connection between excel ana Autocad
Set ExcelApp = Nothing
End Function
Function GetCellValue(row As Integer, column As Integer) As Variant
' This function returns the value of a given cell in excel.
GetCellValue = ExcelApp.ActiveSheet.Cells(row, column).value
End Function
Sub ExcelToAcad()
' declaration of variables
Dim A(2) As Double
Dim B(2) As Double
Dim line1 As AcadLine
Dim circle1 As AcadCircle
ExcelConnect
' giving cell values to points A (from cells C5/D5) and point B (from cells C6/D6)
' The default value for the z coordinate is 0 (drawing in xy plane)
A(0) = GetCellValue(5, 3) ' Ax
A(1) = GetCellValue(5, 4) ' Ay
B(0) = GetCellValue(6, 3) ' Bx
B(1) = GetCellValue(6, 4) ' By
Set mspace = ThisDrawing.ModelSpace
' creating a line from A to B
Set line1 = mspace.AddLine(A, B)
' Creating a circle with center at point A and a diameter of 0.2 drawing units
Set circle1 = mspace.AddCircle(A, 0.2)
' Regenerating the active Viewport
ThisDrawing.Regen (acActiveViewport)
' Closing the excel-autocad link
ExcelClose
End Sub
anybody can help about this code? im trying to copy and paste to autocad vba but not running... any suggestion plssss... ty