Home AutoCad VB Run AutoCad Macro from Excel
23 | 02 | 2012
Main Menu
Search
Paypal Donation
So we can continue and expand this site
Content View Hits : 469530
Run AutoCad Macro from Excel PDF Print E-mail
User Rating: / 0
PoorBest 
Tutorials

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.

Show/Hidden vbnet code

View source
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")
 
	Else
 
	Set objAcad = CreateObject("AutoCAD.Application")
 
	End If
 
 
 
	objAcad.Visible = True
 
	Set ThisDrawing = objAcad.ActiveDocument
 
 
 
	Dim FileName As String
 
	FileName = PROJECTPATH
 
	' 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_Here:
 
	Exit Sub
 
	Err_Control:
 
	MsgBox Err.Description
 
	Resume Exit_Here
 
	End Function

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


Show/Hidden vbnet code

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

 

Comments  

 
0 #1 2011-05-04 16:54
asdasdas
Quote
 

Add comment


Security code
Refresh

Advertising

LOGON
Sponsored Links