power4XL Microsoft Excel Resource Center
Free Macros, Formulas, Functions, Tutorials, Downloads, Add-Ins & More!

Incorporating a VBA user form

ShareThis

Though, as with worksheet controls, it is beyond the scope of this tutorial to give detailed instruction on the design and use of forms in Visual Basic, we do offer a brief introduction here as they can add great flexibility to your models.

A key benefit is that they allow interaction with your VBA program during run-time. 

In the FastSlow example, clicking the "Run FastSlow1" button on the worksheet causes the FastSlow User Form (below) to appear.

From this form the user chooses to run the model in "Fast" or "Slow" mode.  The user's input is read into the VBA code as a variable, and the code uses that value in "if - then" blocks to determine what gets processed.

To incorporate a User Form in your VBA program, select "Insert - UserForm" from the drop-down menu in the Visual Basic Editor.

This inserts a blank User Form into your project, which you can then modify using the Controls Toolbox within the Visual Basic Editor.

 

Prev | Contents | Next

Copyright notice:  This site and all content, including computer code and spreadsheet examples, are copyright 2006 by Fritz Dooley.  License is granted for individual users to download examples and to copy code directly into user's spreadsheets and Visual Basic for Applications files.  Users may not redistribute code in any way.  Providing hyperlinks to this web site is encouraged, but posting code and examples on other web sites is expressly forbidden.  "Microsoft" is a registered trademark of Microsoft Corporation.   Neither this web site nor Fritz Dooley is affiliated with Microsoft Corporation.