Simple example with recording code


Simple Example – recorded VBA macro

There are different development levels to create VBA code create or manipulate and remove data.

One method is to execute commands in MicroStation and record these steps as a macro and save this as VBA code. There are just a view steps required in order to get a recorded macro:

Go to the Utilities Tab of the Ribbon menu and select the “Record” button within the Macros Ribbon:

Please note: with a click on the “Record” button the button changes to “Pause” to let us know the steps from now are recorded.

After executing the desired steps in MicroStation a click on “Stop” ends the recording and a new dialog opens to ask for a project name to save the macro:

Please note: the Button in the lower left corner. This button expands the dialog and allows to select between “Bentley” and “VBA”. If the default “Bentley” is selected, the recording is saved as binary BMR format.

Please select “VBA”, browse to the desired location and press “Save”. This will save the project in a new MVBA project file. The name of the VBA project just used to save the recording is now also added into the Macros Ribbon, please note the entry “Bmrrecordtest”:

A click on the pencil symbol on the right of the name opens the VBA editor with the previous created VBA macro:

 

For this recording I used the “Place Smartline” keyin in MicroStation and in the recorded VBA code I can find this line:

CadInputQueue.SendKeyin " PLACE SMARTLINE"

This is how a MicroStation keyin is used in a VBA program to start a command. To learn more about the .SendKeyin method click on the word to position the cursor for context sensitive help and press the F1 key for help. This will open the MicroStation VBA help and show the help like this:

If you want to learn more about “CadInputQueue” do the same or search directly in the help:

Please note: Some keywords on the help provide link to code example, like here for CadInputQueue. If you click on “Example”, you may select from a larger number of examples:

If just select the first example to get this complete VBA code example:

Within the MicroStation VBA help there are a lot of code examples to demonstrate the use of the different methods. Please note: Make sure to use a MicroStation keyword before using F1 for sensitive help, otherwise the general VBA help opens, which helps with general VBA keyword, but does not contain help for MicroStation  classes.

The MicroStation VBA helpfile can also be opened outside the VBA Editor. The name of the help file is MicroStionVBA.chm and is stored in the same folder with MicroStation.exe.