There is often a need to run a VBA subroutine with a shortcut in order to use a keyin as a part of a batch, to integrate the call into a menu, or so the execution can be carried out by a button press.
This VBA sample is created to give users without previous knowledge of VBA the opportunity to try a simple example on their own.
To create a VBA routine in Microstation, click the "Project Manager" option under the "Utilities" dropdown menu under "Macro".
In the Project Manager, a default.mvba file is usually already loaded, which is shown in the following window. Creating a new project is done by clicking the "New Project" icon shown in the following window:
The "New Project" menu opens a Save dialog to create a .MVBA file. It is reccomeded to accept the default path (The VBA directory in the Microstation Workspace), so there will be no need to key in your specific patch in the subsequent Keyin browser.
I have chosen to name the project "Test". Once you have created a new project, we can open it in the VBA editor. Highlight the project you just created, and click the "Visual Basic Editor" icon (5th button in the toolbar).
Under the "test" project is an automatically created module named "Module1". Double-clicking on "Module1" will open a pane in the input area for the program's code. Here, we have a simple exmplae that opens a dialog box. The subroutine name, project name, and module name circled below will be needed during the Keyin process.
The program code only includes these 3 lines:
Sub mytest () MsgBox "Hello world" End Sub
A VBA subroutine can be loaded and started via the following general Keyin:
VBA RUN [Projectname]Modulname.Subroutine
In our example, it is the following command:
vba run [test]module1.mytest
If there are no other modules in the project, the module name may be omitted:
vba run [test]mytest
If the VBA project is already loaded and there are not several subroutines defined with the same name in multiple projects, the project name can be omitted, giving us the shortest Keyin:
vba run mytest
The dialog box opens when the specific keyin is run:
For questions or problems, please contact Technical Support