21 | 08 | 2017

Run AutoCad Macro from Excel

There are situations where it can be usefull to load a AutoCad project from Excel. You don't have to set the AutoCad reference in Excel. The only thing the code does is startup AutoCad and load another Project.

Public Function RUNproject(ByVal PROJECTPATH As String, ByVal MACRONAME As String)

Dim AcadRunning As Boolean

'On Error GoTo Err_Control
AcadRunning = IsAutoCADOpen()

If AcadRunning Then
Set objAcad = GetObject(, "AutoCAD.Application")
Set objAcad = CreateObject("AutoCAD.Application")
End If

objAcad.Visible = True
Set ThisDrawing = objAcad.ActiveDocument

Dim FileName As String
' Load a sample VBA project DVB file create with AutoCAD
objAcad.LoadDVB FileName
' Run the macro
objAcad.RunMacro MACRONAME 'enter the module and routine/function name

Exit Sub
MsgBox Err.Description
Resume Exit_Here
End Function

Test the function with a code that looks somewhat like this:


Sub TSTproject()
'Test the function
RUNproject "C:\Testproject.dvb", "MODULENAME.ROUTINENAME"
End Sub

Sign up now and upload your code to the website.

Help us to continue.....
Articles View Hits
Latest Articles