VBA Editor


VBA and especially access to the VBA Editor is fully integrated into MicroStation. To customize VBA in the MicroStation configuration these 4 configuration variables are supported:

MS_VBAAUTOLOADPROJECTS: Names of the projects that are opened when the VBA dialog box is opened.  This allows to enable eventhandler on loading projects.

MS_VBANEWPROJECTDIRECTORY: Directory that is used when a new project is created.

MS_VBASAVEONRUN: If set to 1, MicroStation automatically saves modified VBA projects every time it starts running a VBA program.

MS_VBASEARCHDIRECTORIES: Directories that are searched when opening an existing VBA project. This is very helpful to allow executing of VBA subroutines just by name.

The values of these variables can be retrieved and customized from MicroStation Backstage > Settings > Configuration > Configuration Variables.

 

There are different alternate ways to get access to the VBA Editor and to execute  VBA subroutines. In MicroStation CONNECT Edition the VBA related functions and Editor can be retrieved by MicroStation Keyins:

Macro vba show (can be used to open the VBA Editor)

Some common used examples to load and execute VBA routines:

Macro vba run [project]module.subroutine macro vba run [test]module1.main (is loading and executing VBA subroutine main in project test, Module name = module1. The project needs to be stored in folder listed with MS_VBASEARCHDIRECTORIES)                macro vba run [test]main  (if the name of the subroutine is unique in the project, module name is optional)

Macro vba load <path and name to mvba project> (load a project from any location providing path) macro vba load c:\macros\test.mvba Macro vba load <name to mvba project> (load a project from folder in MS_VBASEARCHDIRECTORIES) macro vba load test Macro vba execute [project]module.subroutine macro vba execute [test]module1.main

Macro vba new <filename> macro vba new test    (creates a new vba project test.mvba in folder where MS_VBANEWPROJECTDIRECTORY points to) macro vba new c:\macros\test.mvba (creates the project in given path)

Note: the first word “Macro” for many of these keyins is optional to keep compatible to v8i and previous releases

The VBA Editor also can be opened with the ALT-F11 shortcut if there are any VBA projects loaded into the VBA Editor If there are not yet loaded any VBA projects, the VBA project Manager can be opened from the Macros Ribbon in the Utilities Tab:

The VBA project Manager looks like this and is providing a list of projects locates in the folders listed by MS_VBASEARCHDIRECTORIES. Right to the name are 2 columns to indicate if this project is loaded and if this project is loaded automatically (means is listed in MS_VBAAUTOLOADPROJECTS). A click on these columns is negating the state. If a project from another location should be used, please use the folder icon in the icon command list and click on the pencil symbol to open the VBA editor:

The open VBA Editor may look similar to this:

By default in the upper left corner the loaded VBA projects. For each project the modules, classes and userforms are listed:

A click on the + symbol opens the tree view and is listing all subitems:

A double click on one of these items displays the code in a new window by default on the right side:

To execute a VBA Subroutine first click into the source code of the subroutine and click on the play symbol (or press F5):

If there was no Subroutine selected or the cursor is outside a Subroutine, a new dialog opens with a listing of all loaded subroutines to allow to select from there, this may look like this:

If you want to execute a subroutine from here, select from the list and press “Run”.