Creating a macro to display the dialog box

The only thing missing is a way to display the dialog box. Follow these steps to make the procedure that makes the dialog box appear:

1. In the VBE window, choose InsertOModule.

The VBE adds an empty VBA module (named Module1) to the project.

2. Enter the following code:

Sub ChangeCase()

' Exit if a range is not selected

If TypeName(Selection) = "Range" Then ' Show the dialog box

UserForml.Show End If End Sub

This procedure is simple. It checks to make sure that a range is selected. If not, the macro ends with no action. If a range is selected, the dialog box is displayed (using the Show method). The user then interacts with the dialog box and the code stored in the UserForm's Code pane is executed.

0 0

Post a comment