How to Use the MultiPage Control in a UserForm

This article was previously published under Q155374
This article has been archived. It is offered "as is" and will no longer be updated.
This article explains how to use the MultiPage control in a UserForm andprovides a Microsoft Visual Basic for Applications example.
Use a MultiPage control to work with a large amount of information that canbe sorted into several categories. The MultiPage control allows you tovisually combine and categorize this information on a single form.

The MultiPage control is a container for a collection of Page objects.Each Page object contains its own set of controls and does not necessarilyrelyon other Page objects for information. For example, you can add differentcontrols in the client region for each Page object in the MultiPagecontrol. By default, a MultiPage control contains two pages; you can addor remove pages as needed.

Adding a MultiPage Control to a UserForm

To add a MultiPage control to a UserForm in the Visual Basic Editor,follow these steps:
  1. Click the UserForm to activate it.
  2. On the View menu, click Toolbox to display the toolbox if it is not already displayed.
  3. Click the MultiPage control button.
  4. Draw the MultiPage control on the form.

Working with the Individual Pages in a MultiPage Control

To select an individual page in a MultiPage control, first click theMultiPage control, and then click the page.

NOTE: When you click the MultiPage control, the page at the front of thecontrol is automatically selected.

After you select a page, you can change its properties, delete it, add newpages, or move pages by right-clicking the page and clicking theappropriate command on the shortcut menu.

Working Programmatically with the MultiPage Control

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to 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 requirements. Use the SelectedItem property of the MultiPage control to indicate whichPage object is selected in the MultiPage control at run time. For example,if you create a MultiPage control named MultiPage1, you can use thefollowing statement to display the caption of the selected page:
   MsgBox MultiPage1.SelectedItem.Caption				
The SelectedItem property is read-only and cannot be set at run time. Ifyou need to programmatically set which page is selected, set the Valueproperty for the MultiPage control. The following example selects the thirdpage on MultiPage1:
   MultiPage1.Value = 2				
NOTE: The values of the Pages in a MultiPage control start at zero. Thus,if the control contains three Pages, their values are 0, 1, and 2.


The following example describes how to create a simple UserForm thatimplements a MultiPage control.
  1. In a new workbook in Microsoft Excel, point to Macro on the Tools menu, and then click Visual Basic Editor.
  2. On the Insert menu, click UserForm. Press F4 to activate the Properties window for the UserForm. Next to the Name property of the form, type frmMain and type Customer Information next to the Caption property.
  3. Click the form to select it. Click the MultiPage control on the Toolbox window, and draw a MultiPage control on the form. With the MultiPage control selected, press F4 to activate the Properties window. Type mpgCustomer next to the Name property of the MultiPage control.
  4. Click the first page, and then activate the Properties window by pressing F4. Type pgName next to the Name property, and type Name next to the Caption property.
  5. Click the second Page, and activate the Properties window by pressing F4. Type pgLocation next to the Name property, and type Location next to the Caption property.
  6. Click the Name page, and add the following controls with the listed property settings:
        Control Type          Property                Value    ----------------------------------------------------------    Label                 Name                    lblFirstName                          Caption                 First Name    TextBox               Name                    txtFirstName    Label                 Name                    lblLastName                          Caption                 Last Name    TextBox               Name                    txtLastName						
  7. Click the Location page, and add the following controls with the listed property settings:
        Control Type          Property                Value    ----------------------------------------------------------    Label                 Name                    lblRegion                          Caption                 Region    TextBox               Name                    txtRegion						
  8. Click the CommandButton on the Toolbox window, and add one CommandButton control on the form outside of the MultiPage control. Draw the CommandButton control in the upper right corner of the form. Type OK next to the Caption property for the CommandButton, and type cmdOK next to the Name property.
  9. Right-click the OK CommandButton control, and click View Code. Type the following code:
           Private Sub cmdOK_Click()          ' Save the data in the TextBox controls to the          ' active worksheet.          With ActiveSheet             .Range("A1") = Me.txtLastName.Text             .Range("B1") = Me.txtFirstName.Text             .Range("C1") = Me.txtRegion.Text          End With          ' Unload the form.          Unload Me       End Sub						
  10. On the Insert menu, click Module to insert a module into the project.
  11. Type the following procedure in the Code window of the new module:
           Public Sub ShowForm()          ' This procedure displays the form named frmMain.          frmMain.Show       End Sub						
  12. With the insertion point in the procedure ShowForm, press F5 to run the macro.
After you type values into the text boxes on the two Pages, click OK. Thevalues from the text boxes will be inserted in the appropriate cells in theworksheet, and the UserForm will be dismissed.
For more information about the MultiPage Control:
  1. Create a MultiPage control on a UserForm.
  2. Click the MultiPage control, and press F1.
custom dialog tabbed xl97 XL98 XL

Article ID: 155374 - Last Review: 12/04/2015 15:18:16 - Revision: 2.2

Microsoft Excel 97 Standard Edition, Microsoft Excel 98 for Macintosh

  • kbnosurvey kbarchive kbdtacode KB155374