Running A VBA Routine by Keyin
Running A VBA Routine by Keyin
Applies To
Product(s): MicroSta on
Version(s): 08.11.09.578
Area: Programming
Subarea: VBA
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".
https://communities.bentley.com/products/microstation/w/microstation__wiki/21821/running-a-vba-routine-by-keyin 1/5
2/17/2020 Running a VBA Routine by Keyin - MicroStation Wiki - MicroStation - Bentley Communities
Previewing Staged Changes
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.
https://communities.bentley.com/products/microstation/w/microstation__wiki/21821/running-a-vba-routine-by-keyin 2/5
2/17/2020 Running a VBA Routine by Keyin - MicroStation Wiki - MicroStation - Bentley Communities
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.
Fullscreen
1 Sub mytest ()
2 MsgBox "Hello world"
3 End Sub
https://communities.bentley.com/products/microstation/w/microstation__wiki/21821/running-a-vba-routine-by-keyin 3/5
2/17/2020 Running a VBA Routine by Keyin - MicroStation Wiki - MicroStation - Bentley Communities
A VBA subroutine can be loaded and started via the following general Keyin:
If there are no other modules in the project, the module name may be omitted:
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:
https://communities.bentley.com/products/microstation/w/microstation__wiki/21821/running-a-vba-routine-by-keyin 4/5
2/17/2020 Running a VBA Routine by Keyin - MicroStation Wiki - MicroStation - Bentley Communities
08.11.09.578 SELECTsupport
https://communities.bentley.com/products/microstation/w/microstation__wiki/21821/running-a-vba-routine-by-keyin 5/5