The information in this article applies to:
- Microsoft Excel for Windows 95, version 7.0
- Microsoft Excel for Windows, version 5.0
- Microsoft Excel for the Macintosh, version 5.0
SUMMARY
In Microsoft Excel, you can create buttons with the text "Previous" and
"Next" that allow you to move between custom dialog boxes.
MORE INFORMATION
Microsoft provides programming examples for illustration only, without
warranty either expressed or implied, including, but not limited to, the
implied warranties of merchantability and/or fitness for a particular
purpose. This article assumes that you are familiar with the programming
language being demonstrated and the tools used to create and debug
procedures. Microsoft support engineers can help explain the functionality
of a particular procedure, but they will not modify these examples to
provide added functionality or construct procedures to meet your specific
needs. If you have limited programming experience, you may want to contact
the Microsoft fee-based consulting line at (800) 936-5200. For more
information about the support options available from Microsoft, please see
the following page on the World Wide Web:
http://www.microsoft.com/support/supportnet/refguide/default.asp
The following steps show you how to set up four dialog boxes with Next and
Previous buttons.
- Enter the following into a Visual Basic module sheet:
Public x As Integer
Sub ShowDialog()
' Start with Dialog two.
x = 2
Do
' Show the Dialog; if Cancel is pressed, exit the Do Loop.
If DialogSheets(x).Show = False Then Exit Do
Loop
End Sub
Sub PreviousDialog()
'Hide the current dialog
DialogSheets(x).Hide
' Sets the index to one previous.
x = x - 1
' Test if we are going to show the first dialog box.
If x = 1 Then
' If it is the first dialog box, then disable the Previous
' button.
DialogSheets(x).Buttons("Previous").Enabled = False
End If
End Sub
Sub NextDialog()
' Hide the current dialog box.
DialogSheets(x).Hide
' Sets the index to one next.
x = x + 1
' Test if we are going to show the last dialog box.
If x = DialogSheets.Count Then
' If it is the first dialog box, then disable the Next button.
DialogSheets(x).Buttons("Next").Enabled = False
End If
End Sub
- Add a new dialog sheet.
- Delete the OK button.
- Add two new buttons. Change the caption and name of one to "Previous"
and the other to "Next."
- Assign the "PreviousDialog" macro to the "Previous" button, and
assign the "NextDialog" macro to the "Next" button.
- Copy the dialog box to create three more dialog boxes (total of four for
the example).
NOTE: A quick way to do this is to click Move Or Copy Sheet on the Edit
menu and make copies of the entire dialog sheet.
- Starting from the dialog sheet farthest to the left, change the dialog
boxes caption to "One," "Two," "Three," and "Four" (so you can tell when
the dialog boxes change).
- Run the "ShowDialog" macro, click the Previous and Next buttons to move
between the dialog boxes. The Cancel button will stop the macro.
|