Questions similar to these appear in the Be Communities MicroStation Programming Forum.

This page lists some solutions to common MicroStation VBA (MVBA) problems. Tips are published as examples and are not necessarily working code.

Next File Tool

The Next File tool was developed in response to a request by a MicroStation CONNECT user. He had a BASIC macro from the last century. Because BASIC is not supported by MicroStation CONNECT, he wanted a VBA equivalent.

Next File Tool

The purpose of the tool is to let a user move through the collection of DGN files present in the same folder as the active DGN file. It's a shortcut that saves time by avoiding MicroStation's File|Open menu. Additional capability lets you key-in a command that simulates the user interface, so you can, for example, use function keys to open the next file.

Automatic Loading

The code has the added benefit, compared to its BASIC predecessor, that it can be loaded automatically. The macro includes a class that implements WithEvents and pops the UserForm in the OnProjectLoad event.

Next File Key-Ins

Load the VBA project using key-in
vba run [FileOpener]modMain.main

The DGN File Browser VBA UserForm pops. The UserForm shows the current DGN file (the active DGN file). The Previous  and Next  buttons let you open another DGN file in the same folder as the active DGN file.

With the DGN File Browser showing, you can use another key-in to move through your DGN files …

vba run [FileOpener]modMain.NextFile Simulates pressing the Next or Previous button
vba run [FileOpener]modMain.NextFile + Simulates pressing the Next button
vba run [FileOpener]modMain.NextFile - Simulates pressing the Previous button

Put those last two key-ins in a MicroStation Function Key Menu or custom user interface widget.

You don't need to know anything about VBA to use our tool. If you're not interested in the description of the VBA code that follows, then skip to the download section.

User-Requested Enhancements

Auto Load
The macro will correctly start automatically if specified. You specify that a macro should auto-load using the configuration variable MS_VBAAUTOLOADPROJECTS
Save Dialog Position
The Next File UserForm saves its screen position. When you reload the macro, the UserForm moves itself to the previous position

Next File Tool: Code Overview

VBA class clsNextFile is the primary data holder. On first loading, clsNextFile builds a list of DGN files found in the same folder as the active DGN file. It maintains an index to the current active DGN file. It provides methods to get the next or previous DGN file name in that list.

VBA UserForm frmNextFile is the primary user interface. The Previous  and Next  buttons call the corresponding method in class clsNextFile.

VBA class clsMonitorEvents implements the WithEvents interface. That enables it to respond to the OnProjectLoad and OnDesignFileOpen events. If you configure the VBA project to load when MicroStation starts, then you will see the UserForm appear automatically.

Subroutine NextFile simulates a key-in command. If the Next File tool is not already loaded and showing its UserForm, then this procedure does nothing. If the UserForm is displayed, then this subroutine simulates pressing either the Previous  or Next  button. The optional argument (+ or -) specifies the direction to move.


Download

Download the Next File Tool

You can download the Next File MVBA project. The project includes the MVBA project SequentialFileOpener.mvba.

Next File Tool

MicroStation V8i

If you would like to use this macro with MicroStation V8i, visit the Next File for MicroStation V8i page to download a valid project.