MicroStation Visual Basic for Applications
  • Programming Tips
  • Programming Examples
MVBA

LA Solutions staff have written a number of technical articles. These include programming, MicroStation®, GeoGraphics, and relational databases. Some articles describe aspects of MicroStation software development, and others provide code examples.

You may also find the BE Newsletter useful. It is published by Bentley Systems.


MicroStation® Visual Basic for Applications™ (MVBA)

We've written a miscellany of VBA tips, plus some longer articles listed here. We also answer that common question: "Where is VBA Help?"

VBA Help

MVBA is Bentley Systems' adaptation of the Microsoft VBA toolkit. It provides a subset of Visual Basic™ (VB) functionality and is similar to the VBA implementations in Microsoft Word™, Excel™ and applications from third-parties. A MicroStation installation includes a VBA Help file, which provides extensive documentation and example code.

See our books page for information about books that may be interesting to MicroStation developers.

Where MVBA differs from other VBA implementations is its support for MicroStation. Just as VBA for Microsoft Word provides programming models for words and paragraphs, MVBA provides programming models for graphic elements, reference models, keyin commands, and many other features unique to MicroStation.

MVBA uses VB syntax and is easy to learn: there are many books and other tutorials available for Visual Basic beginners. The Interactive Design Environment (IDE) is similar to the IDE in Word and Excel, and not too dissimilar to the IDE in VB itself.

VBA Tools

VBA Interactive Development Environment

VBA's Interactive Development Environment (IDE) provides a lot of tools to help you. Explore the IDE. Take a VBA training class.

VBA Debugger

VBA includes debugging tools. Function key F8 lets you step through your code and examine the state of your variables. The Debug object is your friend. Debug.Print "Trace message" gives you information that only you can see in the IDE. See also the MicroStation Message Center that can provide debug data to your users.

Mouse Wheel Support

One irritating failing of VBA, and Visual Basic as well, is its lack of support for a mouse wheel. That is, you can't use the wheel on your mouse to scroll through code in the VBA IDE. However, Microsoft has published a fix for this problem. Visit this link to learn how to enable mouse-wheel scrolling in both VB and VBA.

Record a Macro

One of the simplest ways to get started with VBA is to record a macro. Use MicroStation menu Utitilities|Project Manager to pop the VBA Project dialog. The record macro buttons let you capture your user actions as a VBA recording.

VBA record macro buttons
MicroStation® VBA Development
Topic Title Article Location Sample Code
ActiveX Controls ColorPicker Bentley ColorPicker OCX
Administration Configuration Variables Configuration Variables and VBA Configuration Variables and VBA
Databases Databases Databases and MicroStation
Element Manipulation Create a Shape Element Create Shape page CreateShape.zip
Locate an Element given its ID Locate Element page ElementLocator.zip
Mark Circle Centre Add markup to identify the centre of a circle (or ellipse) page MarkCircleCentre.zip
Move an Element Move Element page MoveElement.zip
Events Design File Events Design File Events page OpenCloseEventHandler.zip
Files File Locations File Locations page
Excel™ MicroStation™ VBA and Excel™ VBA and Excel page
GeoGraphics Find Maps about a Point GeoGraphics page
Levels Level Control & Manipulation Level Control Source code included
Iterating Level Libraries (DGNLIBs) Level Libraries Source code included
Measurement Measure Area of Closed Shapes, Grouped Holes & LineStrings Measure Area page Contained in article and MeasureArea.mvba module
Measure the Length of a MultiLine Measure Lines page Contained in article
Measure the Distance Between Parallel Lines Measure Lines page Contained in article
Computing Intersections PDF Document ComputingIntersections.zip
Miscellaneous Navigating the TCB Navigating the TCB page. (Also Navigating the TCB with BASIC)
Clipboard: Cut and Paste with VBA Using the Windows Clipboard Source code included
Arithmetic: truncation & rounding with VBA Numeric Formatting
Is an MDL Application Loaded? Is MDL Loaded page Source code included
Is an element a Grouped Hole? Grouped Hole Page Source code included
MicroStation VBA Tips MVBA Tips page Contained in article
Referencing the MicroStation VBA Object Library elsewhere; referencing other libraries in MicroStation VBA Referencing VBA Object Libraries Included in article
Using MicroStation's Message Center Message Center page Contained in article
Starting a Batch File PDF Document ShellBatch.zip
Validating Configuration Variables Configuration Validator
Verifying a DGN File Check Design File page Sample code that shows how to check if a file is a DGN file
References Log Reference Attachments PDF Document LogRefs.zip
Reference Attachment Operations Reference Attachment Operations page Attach a reference; set a reference clip boundary
Scanning Searching through a Model for specified elements Scanning a Model Included in article
Searching through a Model for named cells Scanning a Model for named cells FindCell.zip
Enumerating Models or Cells Enumerating Models page How to examine the models in a DGN file (a model is a cell; a cell is a model)
Tags Reading and Writing Tag Data Tag Data Overview Included in article
Writing Tag data into a Text File PDF Document TextFileWriter.zip
Text Text Element Analysis & Manipulation Text Element page
Reading a Text File into Coordinates PDF Document TextFileReader.zip
Analysing Text Enter Data Text Enter Data page
Text Styles Text Styles page
Undo Grouping Group Operations in an Undo Group Undo Grouping page
Views MicroStation View Capture Capture View page CaptureView.zip
View Settings and Control View Settings and Control page
Windows File & Folder Browsing Files and Folders Example VB and VBA code available
Open an Office Document Open a Word™, Excel™ or other document in MicroStation
UNC and Drive Paths Compare a UNC path with a Drive path using VB or VBA ComparePaths.zip
MicroStation Title Set MicroStation Title article SetMicroStationTitle.zip
Progress Bar Progress Bar article ProgressBarExample.zip
Windows Common Dialogs Common Dialogs page Contained in article
Win32 Window Handle Window Handle page Contained in article

Visual Basic is not VBA

Microsoft provides Visual Basic for Applications to software vendors in its VBA Toolkit. The vendor uses the VBA Toolkit to implement and customise VBA for their application. VBA generates binary code that is tightly coupled to the host application. The code is in a container whose nature depends on the vendor's policy. For example, a Microsoft Excel™ VBA project is stored in an Excel workbook or add-in. A MicroStation VBA project is stored in a .mvba file.

Visual Basic cannot read a .mvba binary file. If you want to move VBA code to a VB project, then you should export the source code from the VBA project. Export code from the VBA Interactive Development Environment (IDE) by right-clicking in the Project window and choose the Export option from the pop-up menu.