Page 274 - Excel Progamming Weekend Crash Course
P. 274

n540629 ch19.qxd  9/2/03  9:35 AM  Page 249




                  Session 19 — Creating Custom Dialog Boxes with User Forms              249


















                    Figure 19-5 The editor automatically enters the outline of the event procedure in
                    the editing window.

                 3. Enter the single line of code Me.Hide in the procedure, between the opening and
                    closing lines.
                 4. Select cmdMove in the left list.
                 5. In the event procedure for the cmdMove button, enter the single line of code
                    Me.Move 10, 10.
                 6. Click the Save button to save the project.

                  At this point the user form is complete. The next and final step is to add the code to the
               project to display and retrieve data from the form.

                 1. In the Project window, double-click the name of a code module to open its editing
                    window.
                 2. Select Insert ➪ Procedure to display the Add Procedure dialog box.
                 3. Enter TestUserForm as the procedure name and then click OK. The blank procedure
                    is entered into the editing window.
                 4. Enter the code shown in Listing 19-1 into the procedure.


               Listing 19-1  A procedure to display and test the user form

                  Public Sub TestUserForm()

                  Dim s As String
                  Dim frm As New TestForm

                  frm.Show
                  s = frm.TextBox1.Value
                  MsgBox “You entered “ & s

                  End Sub
   269   270   271   272   273   274   275   276   277   278   279