Sunteți pe pagina 1din 5

2/17/2020 Running a VBA Routine by Keyin - MicroStation Wiki - MicroStation - Bentley Communities

Running a VBA Routine by Keyin

Applies To

Product(s): MicroSta on

Version(s): 08.11.09.578

Environment: Windows 7 32 bit,Windows 7 64 bit

Area: Programming

Subarea: VBA

Original Author: Tristan Anderson, Bentley Technical Support Group

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.

The program code only includes these 3 lines:

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:

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:

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

For questions or problems, please contact Technical Support

 VBAWindows 7 32 bit  MicroStation  Windows 7 64 bit  Programming  en

 08.11.09.578  SELECTsupport

Created by Tristan Anderson


When: Fri, Jun 5 2015 8:19 PM

Last revision by Tristan Anderson


When: Mon, Jun 8 2015 11:14 PM
Revisions: 4
Comments: 0

 0 comments  1 member is here

https://communities.bentley.com/products/microstation/w/microstation__wiki/21821/running-a-vba-routine-by-keyin 5/5

S-ar putea să vă placă și