Page 463 - Microsoft Office Excel 2003 Programming Inside Out
P. 463

Part 5:  Manipulating Excel Objects

                                                  Creating Advanced User Forms
                              Any time the Value property of the MultiPage control is changed, the control’s Change event
                              is fired. The MultiPage1_Change event found in the user form module is the real heart of the
                              wizard’s control. Each possible page value is tested and the code appropriate for that page is
                              executed.

                              Private Sub MultiPage1_Change()
                              If MultiPage1.Value = 0 Then
                                  CommandButton2.Enabled = False
                                  CommandButton3.Enabled = True
                                                                                                              Chapter 20
                                  UserForm1.Caption = "Wizard App - Step 1 of 3"
                              ElseIf MultiPage1.Value = 1 Then
                                  CommandButton2.Enabled = True
                                  CommandButton3.Enabled = True
                                  UserForm1.Caption = "Wizard App - Step 2 of 3"
                              ElseIf MultiPage1.Value = 2 Then
                                  CommandButton2.Enabled = True
                                  CommandButton3.Enabled = False
                                  UserForm1.Caption = "Wizard App - Step 3 of 3"
                                  GenerateOptions
                              Else
                                  MsgBox "Error: invalid page value"

                              End If
                              End Sub

                              For the first page (Value = 0), the Prev button is disabled, the Next button is enabled, and the
                              user form’s Caption property is updated to reflect that this is the first step of the wizard. The
                              Prev button is disabled because it’s impossible to move before the first step in the wizard. If
                              the user wants to end the wizard, the Cancel button can be pressed.
                              On the second page (Value = 1), both the Prev and Next buttons are enabled because the user
                              can choose to press either button. The user form’s Caption property is also updated.
                              On the last page (Value = 2), the Next button is disabled because there are no other steps in
                              the wizard. Unlike the other steps in this wizard, there’s an extra line of code that prepares the
                              information on the form before the form is displayed to the user. A call to GenerateOptions
                              handles the necessary work.
                              If the Value property doesn’t match any of the pages associated with the steps of the wizard,
                              a message box displays an error message. In theory, you should never see this message. In
                              practice, it can be very useful when debugging the navigation logic.








                                                                                                        437
   458   459   460   461   462   463   464   465   466   467   468