In VBA, if you want to have multiple user forms we can have those forms side by side by using MultiPage control where we can show each form as page for each tab. In this article we discuss about how to use MultiPage control in Microsoft Office Excel using VBA.
Open Microsoft Office 2013 Excel => Save it as MultiPageExcel.xlsm Excel Macro-Enabled Workbook.
Open MultiPageExcel.xlsm => right click on Sheet1, select View Code as shown below.
Now go to Insert menu option => select UserForm as shown below to add User Form.
Now Add MultiPage control from ToolBox as shown below. If you not able to find Toolbox, go to View menu and select Toolbox.
It adds the MultiPage control on UserForm as shown below.
By default MultiPage control contains only two pages. We can add more pages to MultiPage control, by right click on MultiPage control tab and select “New Page” as shown below.
We can delete page by selecting “Delete Page” option, can move pages by selecting “Move…” option and we can rename the page by selecting “Rename” option.
We can change the default page by changing the Value property. By default Value property value is 0, if you want to make third page as default page change Value property to 2.
We can add controls to each page of MultiPage control from the Toolbox. If you want to have some common controls for all pages in MultiPage control, add those controls to UserForm instead of adding to MultiPage control.
MultiPage control has some events. Below table explains about these events.
Event Name |
Description |
AddControl |
Occurs when we add any control to MultiPage Control |
BeforeDragOver |
Occurs while we drag and drop any control to MultiPage control |
BeforeDropOrPaste |
Occurs before we drop any object from MultiPage control |
Change |
Occurs when user moves from one page to another page |
Click |
When user clicks on MultiPage control this event occurs |
DblClick |
When user double clicks on MultiPage control this event occurs |
Enter |
Occurs just before the MultiPage control receives focus from another control |
Error |
When any error occurs in MultiPage control it occurs |
Exit |
Occurs immediately after MultiPage control loses its focus |
KeyDown |
Occurs when user press on keyboard |
KeyPress |
Occurs when user press on ANSI key |
keyUp |
Occurs when user releases key on the keyboard |
Layout |
Occurs when MultiPage control size changes |
MouseDown |
Occurs when user presses the mouse button within the border of the control |
MouseMove |
Occurs when user moves the mouse within the border of the control |
MouseUp |
Occurs when user releases the mouse button within the border of the control |
RemoveControl |
Occurs when any control removed from any of the MultiPage control |
Scroll |
Occurs when scroll happened |
Zoom |
Occurs when Zoom value is changed |