Most people only use Visual Basic’s Message Box as an “alert” tool – a way to pass information to the user. Did you know you could use it to pass information back to your macro?

The SOLIDWORKS API class teaches you to declare a variable and set that variable equal to the value returned by MsgBox.


Works great, now the button the user chooses (in this case either a “Yes” or “No” button (most likely in this case “Yes”)) will be stored in the “result” variable.

…but how do you know the values for Yes, No, Cancel, OK? … so you can compare “result” later in your code? I never remember all the different return values for MsgBox, and the help file is too slow. So instead of declaring the variable as a simple integer, I always declare it as the “VbMsgBoxResult” enumerator. Now, any time I access that variable, Visual Basic gives you some nice IntelliSense.

As soon as I click the equals sign, the IntelliSense appears.


This works for .NET programming too except you declare the variable as “MsgBoxResult” instead of “VbMsgBoxResult”