VBA Source Code Samples Written by Rod Wing. Sometimes you need ideas on how to accomplish a certain task in a VBA macro. The VBA Help file is a great place to start for… Read more…
Use key-in commands when learning VBA Written by Rod Wing. Use key-in commands when learning VBA Non-programmers attempting to learn VBA can be easily overwhelmed by the complicated object…
Horizontal scrolling on List Box controls The VBA UserForm List Box control automatically adds a vertical scrollbar when the number of lines exceeds what can be displayed. The same is not true for…
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…
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…
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…
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…
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…
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…
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…
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…
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…
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…
MicroStation GetInput For those of you still wanting to convert MicroStation User Commands (UCM’s) to VBA one way to ease your transition is to use the VBA CadInputQueue.GetInput…
MicroStation Element Enumerator Many MicroStation vba’s use the ElementScanCriteria to build a list of elements in a model that match a set of selection criteria. The ElementEnumerator…
String to MicroStation Master Unit Conversion MicroStation allows users to input units as Sub Units by preceding the value with either a colon, “:6”, or two dots, “..6”. Users may also enter unit…
User interface related code only in User Forms A common practice for beginning developers is to place the macro processing code in the OK (or Apply) button click event sub of a User Form. While this may…
Implement VB.Net Style Error Trapping As you may know, Microsoft is phasing out VBA and encouraging developers to start using VB.Net. Some VBA code can be imported in to VB.Net and run without any…
Use VBA Constants and Enums VBA contains many internal constants and enumerated types to provide consistency and more readable code. Some programmers like to bypass these internal types…
Testing Form Text Entries When using VBA forms for gathering text inputs you may want to test the values. This is particularly true when your application is expecting numeric text…
String $ Functions Use $ versions of string functions VBA provides two versions of some of the commonly used string functions such as TRIM and TRIM$, MID and MID$, LCASE and…
Test for empty string Using the VBA Len function to test for empty string values will improve the performance of your applications. Dim strValue as String ' ' Typical method to test…
Preventing Multiple Instances of a Macro It can be easy for a user to start multiple instances of your macro program, especially if it contains non-modal user forms. In some cases this may not be…
Early Binding vs Late Binding When connecting a macro with an external application, like Microsoft Excel, an object variable must be “bound” to an instance of the application’s…
Run an External Program Some macros need to run an external program (or script) as part of its execution. VBA provides the Shell function for this task. While this may be a simple…
Environment Variables In many macros you need access active session environment settings like username, computer name, etc. The easiest way to do this is using Windows environment…
What Version of Windows? Many organizations will have different versions of the windows operating system installed on their users’ computers. Occasionally your macros will need to…
Sorting Layer/Level Names When developing VBA macros for either AutoCAD or MicroStation it is often necessary to display a list of the layers/levels in the active file in either a…
Obtaining Drive Information The Windows Script Host Object Model has many useful properties and methods for dealing with files, folders, disks, etc. One common use is for checking the…
Searching Sub-folders The Windows Script Host Object Model has many useful properties and methods for dealing with files, folders, disks, etc. One common use is for searching for a…
Evaluating Multiple Expressions in an If Statement It is common to have multiple expressions in an If statement using logical operators And, Or, etc. Remember that every expression in the If statement will…
For-Next Loop Optimization The standard syntax for For-Next loops is to repeat the loop counter variable after Next (i.e. Next i). Placing the loop counter variable after Next is not…