---
title: Using Macros and VBA
description: "CAD Programming: Macros and VBA give users an easy way to dip their toes into programming."
image: https://blog.cadalyst.com/hubfs/Editorial%20-%20Misc/2022_Cadalyst/2022_CADProgrColumn/061522_CADPROG/CADProgramming-450.jpeg
---

[![Cadalyst](https://blog.cadalyst.com/hs-fs/hubfs/Cadalyst_logo_w_tagline.png?width=190&height=45&name=Cadalyst_logo_w_tagline.png "Cadalyst")](https://www.cadalyst.com)

- [CAD Management](https://blog.cadalyst.com/cadmanagement) 
    - [CAD Management Articles](https://blog.cadalyst.com/cadmanagement)
    - [CAD Management Newsletter Archive](https://info.cadalyst.com/cad-manager-newsletter-archive)
    - [Just Tell Jo](https://blog.cadalyst.com/just-tell-jo)
- [Design Solutions](https://blog.cadalyst.com/architecture-infrastructure-construction-solutions) 
    - [Architecture, Infrastructure, Construction](https://blog.cadalyst.com/architecture-infrastructure-construction-solutions) 
          - [The Equipped Architect: Generative Design](https://blog.cadalyst.com/the-equipped-architect-generative-design)
          - [DraftSight Insights](https://blog.cadalyst.com/lynn-allens-draftsight-insight)
    - [Product Design & Manufacturing](https://blog.cadalyst.com/product-design-manufacturing-solutions)
- [CAD Hardware](https://blog.cadalyst.com/cadalyst-cad-hardware) 
    - [CAD Tech News Archive](https://info.cadalyst.com/cad-tech-news-archive)
- [Resources](https://info.cadalyst.com/white-papers) 
    - [CAD Cartoon](https://blog.cadalyst.com/cad-cartoons)
    - [Cadalyst Just Tell Jo Newsletter](https://info.cadalyst.com/just-tell-jo)
    - [Cadalyst Videos](https://www.youtube.com/user/cadalystvideos)
    - [Whitepapers & Tips](https://info.cadalyst.com/white-papers)
    - [CAD Benchmark Test](https://info.cadalyst.com/cad-benchmark-test)
    - [CAD Code/Hot Tip Harry](https://cadtips.cadalyst.com/)
    - [CAD Podcasts](https://info.cadalyst.com/podcasts-for-cad-users)

This is a search field with an auto-suggest feature attached.

- There are no suggestions because the search field is empty.

# Using Macros and VBA

By [Andrew G. Roe](https://blog.cadalyst.com/cadmanagement/author/andrew-g-roe)

[AutoCAD](https://blog.cadalyst.com/cadmanagement/tag/autocad) [CAD Management](https://blog.cadalyst.com/cadmanagement/tag/cad-management) [General CAD](https://blog.cadalyst.com/cadmanagement/tag/general-cad) [Programmming](https://blog.cadalyst.com/cadmanagement/tag/programmming) [MicroStation](https://blog.cadalyst.com/cadmanagement/tag/microstation) [VBA](https://blog.cadalyst.com/cadmanagement/tag/vba) [Macros](https://blog.cadalyst.com/cadmanagement/tag/macros) October 20, 2021

CAD Programming: Macros and VBA give users an easy way to dip their toes into programming.

![CAD Programming Logo](https://blog.cadalyst.com/hs-fs/hubfs/Editorial%20-%20Misc/2022_Cadalyst/2022_CADProgrColumn/061522_CADPROG/CADProgramming-450.jpeg?width=320&height=228&name=CADProgramming-450.jpeg)

Many CAD programs (and other programs for that matter) allow you to save significant time by using macros to automate repetitive tasks.  In this column, we’ll focus on MicroStation PowerDraft for the sake of providing a clear example. If you use another CAD program, it may offer a similar macro recorder tool that lets you record multiple steps and play them back to perform the tasks in one step — all without typing any code. Read this column for an overview of macros, and then check for specifics in your CAD package. 

Macros are one of several tools available if you’re interested in customizing or programming in a CAD environment. (See [CAD Programming: Intro for 2021](https://blog.cadalyst.com/cadmanagement/cad-programming-intro-for-2021) for an overview of other options.) You don’t have to know programming to use macros, but they can be a great introduction to programming. In fact, MicroStation lets you convert a recorded macro to a Visual Basic for Applications (VBA) project for further editing and customization. More on that later.

To get started, let’s assume you want to automate insertion of some text in your drawings. This could be a particular note or label that you use over and over. Instead of typing the note each time or copying and pasting the text, you can create a simple macro to accomplish the task with the following steps.

 

### **Record the Macro**

1. With MicroStation running and a blank drawing open, click the **Utilities** tab to display the **Macros** pane.
   
   ![102021CADProg\_fig1](https://blog.cadalyst.com/hs-fs/hubfs/Editorial%20-%20Misc/2021_CAD_Editorial/2021-Programming/2021-10-20-CADPROG/102021CADProg_fig1.jpg?width=450&height=107&name=102021CADProg_fig1.jpg)
2. Click **Record** to start recording your macro.
3. Click the **Annotate** tab and select the **Place Text** tool.
4. In the **Text Editor** window, type some text, such as, “This is a note for my drawing.”
   
   ![102021CADProg\_fig2](https://blog.cadalyst.com/hs-fs/hubfs/Editorial%20-%20Misc/2021_CAD_Editorial/2021-Programming/2021-10-20-CADPROG/102021CADProg_fig2.jpg?width=300&height=49&name=102021CADProg_fig2.jpg)
5. Click a location in the drawing to place the text.
6. Right-click to exit the command.
7. Click the **Utilities** tab again, and click **Stop** to stop recording.
8. When prompted to save the macro, type in a name, such as “TextMacro” and click **Save**.
   
   ![102021CADProg\_fig3](https://blog.cadalyst.com/hs-fs/hubfs/Editorial%20-%20Misc/2021_CAD_Editorial/2021-Programming/2021-10-20-CADPROG/102021CADProg_fig3.jpg?width=350&height=194&name=102021CADProg_fig3.jpg)

Congratulations! You’ve recorded a macro. Now you can play it back to see what you’ve done.

 

### **Play the Macro**

1. Delete the text you placed previously while recording the macro.
2. In the **Utilities** tab, click **Play**.
3. View the text placed in the drawing.
   
   ![102021CADProg\_fig4](https://blog.cadalyst.com/hs-fs/hubfs/Editorial%20-%20Misc/2021_CAD_Editorial/2021-Programming/2021-10-20-CADPROG/102021CADProg_fig4.jpg?width=450&height=329&name=102021CADProg_fig4.jpg)

If this is your first macro, you might be wondering what you’ve achieved. You’ve simply executed a MicroStation command from a macro instead of the normal menu command. The text is always placed at the same location — not providing much value yet. You can increase the value by customizing the macro so you can select a location. To do this, use a MicroStation feature that lets you promote a macro script to a VBA project for further editing and customization.

 

### **Promote the Macro**

1. In the **Utilities** tab, click the pencil icon next to your macro name.
   
   ![102021CADProg\_fig5](https://blog.cadalyst.com/hs-fs/hubfs/Editorial%20-%20Misc/2021_CAD_Editorial/2021-Programming/2021-10-20-CADPROG/102021CADProg_fig5.jpg?width=300&height=116&name=102021CADProg_fig5.jpg)
2. In the window that appears, click the **Promote** icon to promote your macro to VBA.
   
   ![102021CADProg\_fig3](https://blog.cadalyst.com/hs-fs/hubfs/Editorial%20-%20Misc/2021_CAD_Editorial/2021-Programming/2021-10-20-CADPROG/102021CADProg_fig3.jpg?width=350&height=194&name=102021CADProg_fig3.jpg)
3. In the **Utilities** tab, click the **VBA Manager** icon.
4. In the **VBA Projects** window, select your macro and make sure the **Loaded** box is checked.
   
   ![102021CADProg\_fig7](https://blog.cadalyst.com/hs-fs/hubfs/Editorial%20-%20Misc/2021_CAD_Editorial/2021-Programming/2021-10-20-CADPROG/102021CADProg_fig7.jpg?width=250&height=125&name=102021CADProg_fig7.jpg)
5. Click the **Pencil** icon to edit the VBA code for your macro.
6. In the **VBA** window, find your macro by expanding the modules listed on the left side of the window.
   
   ![102021CADProg\_fig8](https://blog.cadalyst.com/hs-fs/hubfs/Editorial%20-%20Misc/2021_CAD_Editorial/2021-Programming/2021-10-20-CADPROG/102021CADProg_fig8.jpg?width=200&height=61&name=102021CADProg_fig8.jpg)
7. Double-click on the macro module to display the code in the VBA window.

Sub BmrTextMacro()  
    Dim startPoint As Point3d  
    Dim point As Point3d, point2 As Point3d  
    Dim lngTemp As Long  
    Dim oMessage As CadInputMessage  
'   Send a keyin that can be a command string  
    CadInputQueue.SendKeyin "TEXTEDITOR PLACE "  
'   XX-MacroComment\_Header-XX  
'   XX-MacroComment\_InsertText-XX  
    CadInputQueue.SendKeyin "TEXTEDITOR PLAYCOMMAND INSERT\_TEXT ""This is a note for my drawing."""  
'   Coordinates are in master units  
    startPoint.X = 5.85984028573692  
    startPoint.Y = 1.8561289704424  
    startPoint.Z = 0#  
'   Send a data point to the current command  
    point.X = startPoint.X  
    point.Y = startPoint.Y  
    point.Z = startPoint.Z  
    CadInputQueue.SendDataPoint point, 1  
'   Send a reset to the current command  
    CadInputQueue.SendReset  
    CommandState.StartDefaultCommand  
End Sub

If this looks like gibberish, don’t despair. You don’t really need to understand it all just yet — only the portion you want to customize.

 

### **Customize the Macro**

To make the macro more useful, let’s explore how to let the user determine the location of the text.

1. In the VBA window, locate the three lines starting with the term “startPoint…” These lines set the text location at the coordinates you selected when recording the macro.
2. Insert an apostrophe (‘) at the beginning of these lines. This converts these lines to comments that are not executed.
3. Add a line just below the commented lines to prompt the user to select a point. (Your coordinate values may differ from this example, depending on the location you picked.
   
   'startPoint.X = 5.85984028573692  
   'startPoint.Y = 1.8561289704424  
   'startPoint.Z = 0#  
   **startPoint = CadInputQueue.GetInput(msdCadInputTypeDataPoint).point**
4. Click the **Play** icon in the VBA window and notice how the program allows you to select a location for the text.
5. Click the **Save** icon to save your work in a VBA program.

Here are some brief highlights of key lines in the macro. If you’ve done any programming, this should be familiar territory. If not, take a deep breath for some VBA programming basics.

The lines starting with “Dim…” are dimension statements that declare variables to be used in the macro — such as the startPoint variable that determines the text location. The term “CadInputQueue …” refers to an object in the MicroStation application programming interface (API) that can be manipulated with various methods and properties.

Methods used in this macro include “SendKeyin,” which sends a command as if you were keying it in at the keyboard, and “SendDataPoint,” which sends information about the location identified by the variable called point.

 

### **Where to Go Next**

If you’d like to learn more about macros and VBA programming in the MicroStation environment, Bentley has some resources online. For starters, check out: [Developers and Programming - Bentley Communities](https://communities.bentley.com/products/programming/). You can also experiment with recording macros using other MicroStation commands. In general, most MicroStation tasks can be recorded as macros and further customized with VBA code.

General information about VBA is prevalent on the Internet and in numerous books. Because VBA was originally introduced by Microsoft for automating tasks in Microsoft Office, many of the same concepts discussed in this article apply to automating tasks in Microsoft Word, Excel, and Access, as well as AutoCAD and other VBA-enabled products. Check out the following on Microsoft’s web site: [Office Visual Basic for Applications (VBA) reference | Microsoft Docs](https://docs.microsoft.com/en-us/office/vba/api/overview/) and [Find Help on using the Visual Basic Editor (microsoft.com)](https://support.microsoft.com/en-us/office/find-help-on-using-the-visual-basic-editor-61404b99-84af-4aa3-b1ca-465bc4f45432).

Also note that VBA has some limitations and is not intended for large, complex programs. It also faces a somewhat uncertain future among some software vendors, but has managed to survive for many years after rumors of its demise first surfaced. For more serious programmers, [Visual Studio.NET](https://visualstudio.microsoft.com/) offers more versatility and more robust features, and also appears to have wide support for the foreseeable future.

For more in-depth MicroStation programming, Bentley’s MicroStation Development Libraries (MDL) provide additional power. APIs are available in both native (C++ and C) and managed (.NET) environments, providing access to the MicroStation object model and DGN design data.

In future articles, I'll continue to explore additional facets of CAD programming, including both AutoCAD and MicroStation examples. If you would like to suggest a topic, feel free to [send me an e-mail](mailto:editors@cadalyst.com).

 

 

[![CAD-PROGRAMMING\_PILLAR\_CTA](https://blog.cadalyst.com/hs-fs/hubfs/Editorial%20-%20Cadalyst%20Website/CAD-PROGRAMMING_PILLAR_CTA.gif?width=400&height=125&name=CAD-PROGRAMMING_PILLAR_CTA.gif)](https://blog.cadalyst.com/cadmanagement/cad-programming-intro-for-2021)

 

 Share This Post 

[![Share on Facebook](https://cdn2.hubspot.net/hubfs/2115715/ADT%20Blog/Social%20Icons/5e0f3c78452ae7d40a6dbfff_002-facebook-logo.svg)](http://www.facebook.com/share.php?u=https%3A%2F%2Fblog.cadalyst.com%2Fcadmanagement%2Fusing-macros-and-vba%3Futm_medium%3Dsocial%26utm_source%3Dfacebook) [![Share on LinkedIn](https://cdn2.hubspot.net/hubfs/2115715/ADT%20Blog/Social%20Icons/5e0f3c78452ae70fe46dc000_001-linkedin-logo.svg)](http://www.linkedin.com/shareArticle?mini=true&url=https%3A%2F%2Fblog.cadalyst.com%2Fcadmanagement%2Fusing-macros-and-vba%3Futm_medium%3Dsocial%26utm_source%3Dlinkedin) [![Share on Twitter](https://cdn2.hubspot.net/hub/2115715/hubfs/ADT%20Blog/Social%20Icons/5e0f3c78452ae7625c6dbffd_home-socicon1.png?width=24&name=5e0f3c78452ae7625c6dbffd_home-socicon1.png)](https://twitter.com/intent/tweet?original_referer=https%3A%2F%2Fblog.cadalyst.com%2Fcadmanagement%2Fusing-macros-and-vba%3Futm_medium%3Dsocial%26utm_source%3Dtwitter&url=https%3A%2F%2Fblog.cadalyst.com%2Fcadmanagement%2Fusing-macros-and-vba%3Futm_medium%3Dsocial%26utm_source%3Dtwitter&source=tweetbutton&text=Using%20Macros%20and%20VBA) [![Share on Email](https://cdn2.hubspot.net/hubfs/2115715/ADT%20Blog/Social%20Icons/001-envelope.svg)](mailto:?subject=Check%20out%20https%3A%2F%2Fblog.cadalyst.com%2Fcadmanagement%2Fusing-macros-and-vba%3Futm_medium%3Dsocial%26utm_source%3Demail%20&body=Check%20out%20https%3A%2F%2Fblog.cadalyst.com%2Fcadmanagement%2Fusing-macros-and-vba%3Futm_medium%3Dsocial%26utm_source%3Demail)

### Andrew G. Roe

Cadalyst contributing editor Andrew G. Roe is a registered civil engineer and president of AGR Associates. He is author of Using Visual Basic with AutoCAD, published by Autodesk Press. He can be reached at editors@cadalyst.com.

[View All Articles](https://blog.cadalyst.com/cadmanagement/author/andrew-g-roe)

![Get The Cadalyst Briefing](https://no-cache.hubspot.com/cta/default/251891/interactive-127202009180.png)

### MORE ON THIS TOPIC

[![Autodesk University 2026: What the Announcements Mean for CAD Teams](https://blog.cadalyst.com/hubfs/Editorial%20-%20Misc/2026_Cadalyst/2026-09_AU2026/Mower.jpg)](https://blog.cadalyst.com/cadmanagement/autodesk-university-2026-what-the-announcements-mean-for-cad-teams)

[Autodesk](https://blog.cadalyst.com/cadmanagement/tag/autodesk) [AutoCAD](https://blog.cadalyst.com/cadmanagement/tag/autocad) [Mechanical](https://blog.cadalyst.com/cadmanagement/tag/mechanical) [Cloud](https://blog.cadalyst.com/cadmanagement/tag/cloud) [Building design](https://blog.cadalyst.com/cadmanagement/tag/building-design) [Infrastructure](https://blog.cadalyst.com/cadmanagement/tag/infrastructure) [AEC](https://blog.cadalyst.com/cadmanagement/tag/aec) [AI](https://blog.cadalyst.com/cadmanagement/tag/ai) [Autodesk University](https://blog.cadalyst.com/cadmanagement/tag/autodesk-university)

## [Autodesk University 2026: What the Announcements Mean for CAD Teams](https://blog.cadalyst.com/cadmanagement/autodesk-university-2026-what-the-announcements-mean-for-cad-teams)

*[Autodesk](https://www.autodesk.com?utm_source=Cadalyst)* held its annual Autodesk University conference in Las Vegas September 15–17, and if there was one word tying the keynotes and product...

<https://blog.cadalyst.com/cadmanagement/autodesk-university-2026-what-the-announcements-mean-for-cad-teams>

[![Design Elevated: What’s New in AutoCAD 2026](https://blog.cadalyst.com/hubfs/Editorial%20-%20Misc/2025_Cadalyst/2025_Sponsored/2025-06-05_USCAD-ACAD2026/AutoCAD2026-opener.jpg)](https://blog.cadalyst.com/cadmanagement/design-elevated-whats-new-in-autocad-2026)

[Autodesk](https://blog.cadalyst.com/cadmanagement/tag/autodesk) [AutoCAD](https://blog.cadalyst.com/cadmanagement/tag/autocad) [Mechanical](https://blog.cadalyst.com/cadmanagement/tag/mechanical) [Cloud](https://blog.cadalyst.com/cadmanagement/tag/cloud) [Building design](https://blog.cadalyst.com/cadmanagement/tag/building-design) [Infrastructure](https://blog.cadalyst.com/cadmanagement/tag/infrastructure) [AEC](https://blog.cadalyst.com/cadmanagement/tag/aec) [AI](https://blog.cadalyst.com/cadmanagement/tag/ai)

## [Design Elevated: What’s New in AutoCAD 2026](https://blog.cadalyst.com/cadmanagement/design-elevated-whats-new-in-autocad-2026)

Each release of AutoCAD brings refinements, including Autodesk’s latest release of AutoCAD 2026. Rather than sweeping UI (user interface) overhauls...

<https://blog.cadalyst.com/cadmanagement/design-elevated-whats-new-in-autocad-2026>

[![AutoCAD 2026 Focuses on Productivity with Speed, AI, and Collaboration](https://blog.cadalyst.com/hubfs/Editorial%20-%20Misc/2025_Cadalyst/2025-04-14_AutoCAD2026/Adsk-2026-SmartBlock-600.png)](https://blog.cadalyst.com/cadmanagement/autocad-2026-focuses-on-productivity-with-speed-ai-and-collaboration)

[Autodesk](https://blog.cadalyst.com/cadmanagement/tag/autodesk) [AutoCAD](https://blog.cadalyst.com/cadmanagement/tag/autocad) [Mechanical](https://blog.cadalyst.com/cadmanagement/tag/mechanical) [Cloud](https://blog.cadalyst.com/cadmanagement/tag/cloud) [Building design](https://blog.cadalyst.com/cadmanagement/tag/building-design) [Infrastructure](https://blog.cadalyst.com/cadmanagement/tag/infrastructure) [AEC](https://blog.cadalyst.com/cadmanagement/tag/aec) [AI](https://blog.cadalyst.com/cadmanagement/tag/ai)

## [AutoCAD 2026 Focuses on Productivity with Speed, AI, and Collaboration](https://blog.cadalyst.com/cadmanagement/autocad-2026-focuses-on-productivity-with-speed-ai-and-collaboration)

AutoCAD has long stood at the core of digital design across industries, serving as a foundational tool for architects, engineers, and designers...

<https://blog.cadalyst.com/cadmanagement/autocad-2026-focuses-on-productivity-with-speed-ai-and-collaboration>

[![Cadalyst](https://blog.cadalyst.com/hs-fs/hubfs/Editorial%20-%20Misc/Cadalyst_logo-trans-3.png?width=270&height=60&name=Cadalyst_logo-trans-3.png "Cadalyst")](https://www.cadalyst.com)

©2026 Longitude Media, LLC. All rights reserved.

- [Privacy](https://info.cadalyst.com/privacy-lm)
- [About Us](https://info.cadalyst.com/about-cadalyst)
- [Fair Trade Statement](https://info.cadalyst.com/fair-trade-policy)
- [Contact Us](https://info.cadalyst.com/contact-cadalyst)
- [Terms of Use](https://info.cadalyst.com/cadalyst-terms-of-use)
- [Linking & RSS](https://info.cadalyst.com/linking-and-rss-terms-of-use)
- [Advertise](https://info.cadalyst.com/advertise-with-cadalyst)

<https://www.linkedin.com/company/2683855> <https://www.instagram.com/cadalystmag/> <https://www.facebook.com/profile.php?id=100063714723687> <https://www.youtube.com/@CadalystVideos>

```json
{
  "@context" : "https://schema.org",
  "@type" : "BlogPosting",
  "author" : {
    "@type" : "Person",
    "name" : "Andrew G. Roe",
    "url" : "https://blog.cadalyst.com/cadmanagement/author/andrew-g-roe"
  },
  "dateModified" : "2023-06-08T11:55:23.451Z",
  "datePublished" : "2021-10-20T12:37:00.000Z",
  "headline" : "Using Macros and VBA",
  "image" : [ "https://blog.cadalyst.com/hubfs/Editorial%20-%20Misc/2022_Cadalyst/2022_CADProgrColumn/061522_CADPROG/CADProgramming-450.jpeg" ],
  "mainEntityOfPage" : {
    "@id" : "https://blog.cadalyst.com/cadmanagement/using-macros-and-vba",
    "@type" : "WebPage"
  },
  "publisher" : {
    "@type" : "Organization",
    "logo" : {
      "@type" : "ImageObject",
      "url" : "https://blog.cadalyst.com/hubfs/Editorial%20-%20Misc/cadalyst_logo.gif"
    },
    "name" : "Longitude Media, LLC"
  }
}
```