Tips Tagged: VBA
VBA Date Comparisons
VBA has native Date functions as well as a Date data type that allow for comparing and storing date information. The DateAdd function returns a future date (or previous date using a negative interval) using the specified interval. The interval can be in seconds, minutes, hours, days, months, weeks, or years. The DateDiff function will [...]
Adding VBA Processing Status with a Cancel Option
Many applications provide a progress bar with a Cancel option for long running processes. VBA does not have a native progress bar control, but you can provide the same type of information with your own “Status” UserForm containing an informational label and a Cancel button. The code below shows how this can be accomplished. The [...]
Unload All UserForms
UserForms in VBA are the primary way to gather user input required for your macro. More complex macros may require the loading and unloading of multiple forms for gathering different types of input, particularly if you are trying to create a “wizard” type of interface. Managing the showing, hiding, and unloading of forms for multi-form [...]
Unit Round Off
In MicroStation the round off of working units is controlled by the Settings > Design File > Working Units > Accuracy setting. This applies to both coordinate input and display in MicroStation tools. Unfortunately there is no automatic conversion for us in VBA. The example function below demonstrates a method that can be used to [...]
Clean Up After Yourself
You have probably heard some of these simple rules of life: – If you open something, close it – If you turn something on, turn it off – If you spill something, wipe it up These same rules apply to macro development. Many programmers get sloppy because they assume the computer will clean up for [...]
VBA Help
MicroStation VBA has a very robust help system with many examples for common tasks. To get help on a VBA function, property, etc. hit F2 on the keyboard to open the Object Browser. Selecting an item in the browser window will display the arguments and return value for the object. For more information right click [...]
Protecting VBA’s
If you have done much MicroStation VBA development at all you realize how easy it is for a casual or curious user to open the VBA Editor and possibly break your code. For internal company deployments you can modify the security on the .mvba files so that these users have read-only access. When distributing your [...]
Using the Macro Recorder to Capture Commands
The MicroStation VBA Macro Recorder is a useful tool beyond just capturing workflows for creating your own macros. A common dilemma for users wanting to create Batch Process scripts, or their own custom toolboxes is knowing the key-in commands they need for the task they want to accomplish. Using the Macro Recorder to capture the [...]
Use Constants for Common Values
Some developers will calculate common values in code every time they are needed in an application. This slows down your application as it has to calculate the value every time. Others will enter in the straight numeric value, which is just frowned upon programming practice. The best way to handle these values is to use [...]
Autorun MicroStation VBA
A common question asked by new VBA developers is how to automatically start a macro when you start MicroStation. There are several steps involved in this process. Set your VBA project to autoload when MicroStation starts. This can be done by either adding the name of your VBA project to the MS_VBAAUTOLOADPROJECTS workspace variable, or [...]