Microsoft KB Archive/141566

= How to Create Next and Previous Buttons in a Custom Dialog Box =

Article ID: 141566

Article Last Modified on 11/23/2006

-

APPLIES TO


 * Microsoft Excel 95 Standard Edition
 * Microsoft Excel 5.0 Standard Edition
 * Microsoft Excel 5.0 for Macintosh

-



This article was previously published under Q141566



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 professionals 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 a Microsoft Certified Partner or the Microsoft fee-based consulting line at (800) 936-5200. For more information about Microsoft Certified Partners, please visit the following Microsoft Web site:

https://partner.microsoft.com/global/30000104

For more information about the support options that are available and about how to contact Microsoft, visit the following Microsoft Web site:

http://support.microsoft.com/default.aspx?scid=fh;EN-US;CNTACTMS

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).</li> Run the "ShowDialog" macro, click the Previous and Next buttons to move between the dialog boxes. The Cancel button will stop the macro.</li></ol>

Keywords: kbcode kbhowto kbprogramming KB141566

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.