VBA Programming Guidelines

AutoCAD Land Desktop ActiveX & VBA

VBA Programming Guidelines


Option Explicit

A good programming practice is to add the Option Explicit declaration at the top of your module. This will require you to declare all variables using the Dim, Private, Public, ReDim, or Static statements. If you attempt to use an undeclared variable name, an error occurs at compile time. This prevents Visual Basic from automatically creating a variant for the undeclared variable on your behalf, which leads to program errors.

For Next Loops

When using a For Next loop to iterate through an object collection use "EXIT FOR" if you need to exit the loop befor conclusion. If a "GOTO" is used to exit the loop the reference count to the object is not cleaned and will create an error condition.


If an AutoCAD Land Desktop object does not display the complete list of properties and methods in the IntelliSense pick list, try assigning the object to a typed variable first. For example:

Dim prefuser As AeccPreferencesUser

Set prefuser = AeccApplication.Preferences.User

' The prefuser object will now correctly display

' all properties and methods with IntelliSense

AutoCAD Land Desktop Enumerated Value

AutoCAD Land Desktop enumerated values are named constants used in the AutoCAD Land Desktop ActiveX Automation methods and properties.

In VBA, you cannot create an instance of an object of the enumerated type. For example:

' Works in VB, but not VBA

Dim borderstyle As eAeccBorderStyle


In VBA, global variables are not released until the VBA project is unloaded. For example, in your project the following variables are declared as global variables:

Option Explicit


Public acad As AcadApplication

Public app As AeccApplication

Public projs As AeccProjects

The objects acad, app, and proj will not be released until the VBA project is unloaded. This is correct behavior but you must refresh the variables when you come back into the VBA code. If you do not refresh the variables, you might not get the latest information. For example, additional projects might be added to the AeccProjects collection.