sumitkr1108 Posted July 27, 2020 Share Posted July 27, 2020 (edited) Hi All I have this excel macro file which open autocad and close also but i want that it should input command to autocad after opening it with this macro. and that should be taken from column D. Through this we can solve may purposes. Is it possible?? can somebody help me with this?? Sub command() Dim dwgname As String Dim dwgpath As String Dim fileRange As Range Dim elem As AcadObject Dim attelem As AcadAttributeReference Dim Array1 As Variant Dim Count As Integer Dim colMax As Long Dim exlTag As String Dim exlValue As String Dim exlHandle As String Dim i As Long Dim activeRow As Long Dim handle As String Dim attDict As AcadDictionary If MsgBox("Do you want to proceed ?", vbYesNo) = 7 Then Exit Sub End If ThisWorkbook.Worksheets("Text").Activate ' activate sheet Range("A1").Activate ' activate first cell With ActiveSheet colMax = ActiveSheet.Cells(1, .Columns.Count).End(xlToLeft).Column End With '1) get Acad application object Dim Acad_app As AcadApplication Dim Acad_Doc As AcadDocument Dim Acad_ModelSpace As AcadModelSpace Dim Acad_PaperSpace As AcadPaperSpace On Error Resume Next Set Acad_app = GetObject(, "AutoCAD.Application") If Err Then Err.Clear Set Acad_app = CreateObject("AutoCAD.Application") If Err Then MsgBox Err.Description Exit Sub End If End If Acad_app.Visible = True 'brings up window state Acad_app.WindowState = acMax 'maximizes AutoCAD application AppActivate Acad_app.Caption 'brings AutoCAD application in front '1) ends here______________________________________ Set fileRange = ActiveSheet.Range("B2") Do While Not (IsEmpty(fileRange)) '2) open dwg file dwgname = fileRange.Value dwgpath = fileRange.Offset(0, 1) If Right(dwgpath, 1) <> "\" Then dwgpath = dwgpath & "\" ' append \ if missing in last of path End If ' check if dwg file is already opened If Acad_app.Documents.Item(dwgname) Is Nothing Then ' open dwg file if not already opened Set Acad_Doc = Acad_app.Documents.Open(dwgpath & dwgname, 0) Else ' activate dwg file if already opened Set Acad_Doc = Acad_app.Documents.Item(dwgname) Acad_Doc.Activate End If '2) ends here______________________________________ activeRow = fileRange.Row 'find current row number ' set block object from handle number in cell comment Set elem = Acad_Doc.HandleToObject(Cells(activeRow, 4)) elem.TextString = fileRange.Offset(0, 2).Value Set fileRange = fileRange.Offset(1, 0) If Acad_Doc.Name = fileRange.Name Then 'if next row also contains same file name Acad_Doc.Save 'save only Else Acad_Doc.Close True 'save and close End If Loop Acad_app.WindowState = acMin 'minimizes AutoCAD application MsgBox "Updated !" End Sub Edited July 27, 2020 by CADTutor Moved code to code block Quote Link to comment Share on other sites More sharing options...
BIGAL Posted July 28, 2020 Share Posted July 28, 2020 Have a look at this excel vba draw acad.txt Quote Link to comment Share on other sites More sharing options...
sumitkr1108 Posted July 28, 2020 Author Share Posted July 28, 2020 4 hours ago, BIGAL said: Have a look at this excel vba draw acad.txt 3.07 kB · 22 downloads Thanks sir but i think you had posted the same content which i think is for my previous post. I want the above macro to be modified in such manner that it take command from the D column for the clarity i am attaching the file TEST.xls Quote Link to comment Share on other sites More sharing options...
BIGAL Posted July 28, 2020 Share Posted July 28, 2020 I posted how you would make circles using excel reading values form other columns. Just select the column D values copy then paste to Autocad command line LT ok also. No code needed. If you insist on pasting a string look into sending Autocad strings to command line using VBA. This is VL will be similar (vla-sendcommand acdoc "Circle 0,0 1.0") Quote Link to comment Share on other sites More sharing options...
sumitkr1108 Posted July 29, 2020 Author Share Posted July 29, 2020 8 hours ago, BIGAL said: I posted how you would make circles using excel reading values form other columns. Just select the column D values copy then paste to Autocad command line LT ok also. No code needed. If you insist on pasting a string look into sending Autocad strings to command line using VBA. This is VL will be similar (vla-sendcommand acdoc "Circle 0,0 1.0") sir thank for your effort but i dont know vba coding i am new to all these thing. can you creat excel having this vba creating button so that will take command from column D and execute it in autocad but it should take the path from column C and file name from column B. If you can please create that i will be thankful to you Quote Link to comment Share on other sites More sharing options...
BIGAL Posted August 1, 2020 Share Posted August 1, 2020 As you want multi dwgs you need to use a script, this is easy in excel just use =contcatenate("open ",b2,c2," circle 0,0,0 ","close Y") not tested copy the column to notepad and save as a script, then run using Script. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.