Debugging in MicroStation VBA – Visual Basic for Application

VBA is providing a full IDE (integrated development environment) to allow access to all required components like object library, debugger and documentation from the IDE.

VBA is integrated with Microstation and there are several ways to get access to the VBA tools.

VBA is integrated in the MicroStation Utilities Ribbon Tab Macros and can be accessed from here:

Also the main keyin “macro”  allows to direct access to create, edit, execute VBA and BMR macros:

The additional shortcut ALT-F11 directly opens the VBA editor. If there is no VBA project load ALT-F11 returns with an entry to the Message center to remind loading a VBA project before opening the VBA editor. This can be done using the VBA Ribbon entries “VBA Manager” or “Open Macros”

The open VBA Editor may look like this and the VBA project Explorer is listing all loaded projects, by default on the left side:

The module, class or userform content is displayed by default on the right side of the Editor

The “Debug” menu shows all options which can be used to debug a project:

Breakpoints can be added or removed with a single click into the light gray column left to the source code and are marked with a dark red point and highlighted code line:

TIP: Alternately for both Experienced VBA developers or those just Getting Started with Microsoft VBA there may be times when Debugging Microsoft VBA Applications using a "STOP" statement in your code may work best. This can be helpful during certain Microsoft and/or MicroStation VBA specific workflows, like: e.g. Launching VBA Applications using the OnProjectLoad event; where opening the Microsoft VBA Editor to manually set a BreakPoint (Insert or Toggle) as described in this topic may not be possible or convenient.

There are different methods to execute the VBA code:

If the MVBA project filename is stored in a folder listed in the MicroStation (MS) configuration variable MS_VBASEARCHDIRECTORIES, the following keyin can be used to start a subroutine:

macro vba run [project]module.subroutine

The keyin

vba run [project]module.subroutine

from V8i and previous versions can still be used for compatibility reasons

If the VBA project is stored at any other location, the project file first needs to be loaded in order to be executed, example:

[macro] vba load d:\programming\vba7projects\test.mvba [macro] vba execute [test]textstyletest.textstylesave

(the keyword macro is optional as well for these keyins)

If a breakpoint is set and during the execution a breakpoint is reached, the execution halts at this position, this is marked with a yellow highlighted line of code like this:

This halt allows to verify the content of variables listed in the windows for “locals” or “Watches”:


The execution can be continued using the play icon in the VBA editor shortcuts or F5:


The play icon or F5 also can be used to start the execution of a VBA subroutine, the position of the cursor decides which subroutine is started. If nothing is marked, a dialog box with loaded macros opens to allow the user to select from:


Context sensitive help for VBA keywords can be reached using the F1 key. It is important to notice, that 2 different VBA help files are available, one for the general VBA commands and one for the MicroStation related commands. Which of these help files are opened depends on the position of the cursor. E.g. the cursor is positioned in the source code on the keyword “ActiveDesignfile” a click on F1 opens the help for the MicroStation keyword ActiveDesignFile:

Please note the header of the Help file points to MicroStation VBA documentation.

In any other cases the general VBA help is opened, like here with a previous click on the keyword “Dim”:



The VBA also allows to review the complete object library of the referenced libraries. From the menu “View” > Object Browser or F2 the Object libraries are listed like here:


From the drop down list a specific library can be selected to obtain the details from. All classes with available properties and methods are listed. The search field allows to search for a class, property or method. E.g. the search for “textstyles” and click on method “Find” also provides the function declaration for the method Find:



The context sensitive help also works in this view and the key F7 let the user come back to the code view.