VBA sample code to send command from Excel to AutoCAD to draw a rectangle.
Option Explicit
Sub DrawRectange()
Dim AutocadApp As Object
Dim SectionCoord(0 To 9) As Double
Dim Topbar As Integer
Dim BottomBar As Integer
Dim Cover As Integer
Dim Rectang As Object
Dim ActDoc As Object
Dim InsertP(2) As Double
Dim CirObj As Object
Dim i As Long
'****** Launch Autocad application****
On Error Resume Next
Set AutocadApp = GetObject(, "Autocad.application")
On Error GoTo 0
If AutocadApp Is Nothing Then
Set AutocadApp = CreateObject("Autocad.application")
AutocadApp.Visible = True
End If
''****Read Input****
SectionCoord(0) = 0: SectionCoord(1) = 0
SectionCoord(2) = ActiveSheet.Range("f5").Value: SectionCoord(3) = 0
SectionCoord(4) = ActiveSheet.Range("f5").Value: SectionCoord(5) = ActiveSheet.Range("f6").Value
SectionCoord(6) = 0: SectionCoord(7) = ActiveSheet.Range("f6").Value
SectionCoord(8) = 0: SectionCoord(9) = 0
Topbar = ActiveSheet.Range("f8").Value
BottomBar = ActiveSheet.Range("f9").Value
Cover = ActiveSheet.Range("f10").Value
''****Draw rectangle****
Set ActDoc = AutocadApp.ActiveDocument
If ActDoc Is Nothing Then
Set ActDoc = AutocadApp.Documents.Add
End If
Set Rectang = ActDoc.ModelSpace.AddLightWeightPolyline(SectionCoord)
AutocadApp.ZoomExtents
Set AutocadApp = Nothing
Set ActDoc = Nothing
Set Rectang = Nothing
End Sub
How to use this program?
Watch video tutorial HERE ON YouTube
See beam detailing from Excel here
See this post on how to draw beam section in AutoCAD from Excel here

Hi, very intresting thing to create rectangle by vba. But I have a question, how using vba create rectangle with Mtext inside into rectagle and after creation move them or put them in place by my coordinates which are into excel file. For example: I have an excel file which contained 10 different Text, dimentions of rectangle, coordinaties value for rectangle with text I have to put. I gess i need to use some loop for my 10 examples but I don’t know how i can to combined all those things in to vba code. If you can help me, this is will be awsome. Thanks