Chapter 37. Programming with Visual Basic for Applications


  • Understanding VBA and AutoCAD

  • Writing VBA code

  • Getting user input

  • Creating dialog boxes

  • Modifying objects

  • Creating loops and conditions

  • Debugging and trapping errors

Visual Basic for Applications (VBA) is a programming language and environment that is included with many Microsoft applications, such as Word, Excel, PowerPoint, and Access. Since Release 14, VBA has been available with AutoCAD as well. VBA is ideally suited for situations in which you need to work with more than one application at a time. ActiveX, which I discussed in the last chapter in relation to Visual LISP, enables you to access objects in other applications. However, you can also use VBA to program AutoCAD alone. This chapter introduces you to VBA and shows how you can start to use this powerful language to customize AutoCAD.


AutoCAD LT does not support VBA. This entire chapter applies to AutoCAD only.

Visual Basic for Applications is a variation of Visual Basic. Visual Basic is not related to any specific application. Visual Basic code is compiled into an executable file that stands alone, unrelated to any specific document. VBA, on the other hand, is connected to its application and the document in which you created the code. VBA provides a simple way to customize AutoCAD, automate tasks, and program applications from within the application.

VBA in AutoCAD works slightly differently from VBA in most other applications, in that VBA projects ...

Get AutoCAD® 2008 and AutoCAD LT® 2008 Bible now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.