how to use the tabstrip control in a userform

3
Article ID: 155009 - View products that this article applies to. This article was previously published under Q155009 This article explains how to use the TabStrip control in a UserForm and provides a Microsoft Visual Basic for Applications example. 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 a TabStrip control to view different sets of information for related controls. A TabStrip is recommended if you use a single layout for your data. For example, use different tabs in a TabStrip control to display different "views" for one group of controls. The TabStrip is implemented as a container of a Tabs collection, which in turn contains a group of Tab objects. By default, the control contains two Tab objects; you can add or remove Tab objects as needed. The client region of a TabStrip control is not a separate form. Instead, the region is a portion of the form that contains the TabStrip control. The border of a TabStrip control defines a region of the form that you can associate with tabs. When you place a control in the client region of a TabStrip, you are adding a control to the form that contains the TabStrip. Adding a TabStrip Control to a UserForm To add a TabStrip 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. 3. Click the TabStrip control button. 4. Draw the TabStrip control on the form. Working with Existing Tabs in a TabStrip Control To select an individual tab in a TabStrip control, follow these steps: How to Use the TabStrip Control in a UserForm SUMMARY MORE INFORMATION

Upload: iswar-rauf-aboo-aqilah

Post on 14-May-2017

231 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: How to Use the TabStrip Control in a UserForm

Article ID: 155009 - View products that this article applies to.

This article was previously published under Q155009

This article explains how to use the TabStrip control in a UserForm and provides a Microsoft Visual Basic for Applications example.

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 a TabStrip

control to view different sets of information for related controls. A TabStrip is recommended if you use a single layout for your data. For example, use different

tabs in a TabStrip control to display different "views" for one group of controls.

The TabStrip is implemented as a container of a Tabs collection, which in turn contains a group of Tab objects. By default, the control contains two Tab objects;

you can add or remove Tab objects as needed.

The client region of a TabStrip control is not a separate form. Instead, the region is a portion of the form that contains the TabStrip control.

The border of a TabStrip control defines a region of the form that you can associate with tabs. When you place a control in the client region of a TabStrip, you

are adding a control to the form that contains the TabStrip.

Adding a TabStrip Control to a UserForm

To add a TabStrip 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.

3. Click the TabStrip control button.

4. Draw the TabStrip control on the form.

Working with Existing Tabs in a TabStrip Control

To select an individual tab in a TabStrip control, follow these steps:

How to Use the TabStrip Control in a UserForm

SUMMARY

MORE INFORMATION

Page 2: How to Use the TabStrip Control in a UserForm

To select an individual tab in a TabStrip control, follow these steps:

1. Select the TabStrip control.

2. Press the SHIFT key and click the tab that you want to select.

After you select a tab, you can change the tab properties, delete the tab, add new tabs, or move tabs by right-clicking the selected tab and clicking the

appropriate command on the shortcut menu.

Controlling a TabStrip Programmatically

Use the SelectedItem property of the TabStrip control to indicate which Tab object is selected in the TabStrip control at run time. For example, if you create a

TabStrip control named TabStrip1, you can use the following statement to display the caption of the selected Tab:

The SelectedItem property is read-only and cannot be set at run time. If you need to programmatically set which tab is selected, set the Value property for the

TabStrip control. The following example selects the third tab on a TabStrip named TabStrip1:

NOTE: The values of tabs in a TabStrip control start with zero. If the TabStrip control contains three tabs, their values are 0, 1, and 2.

Example

The following example describes how you can create a simple UserForm that implements a TabStrip 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 form. Next to the Name property of the form, type frmMain, and

type Choose a Color next to the Caption property.

3. Select the form. Click the TabStrip control on the Toolbox window and draw a TabStrip control on the form. With the TabStrip control selected, press F4 to

activate the Properties window. Type tbsColor next to the Name property.

4. To select the first tab in the TabStrip control, press the SHIFT key and click Tab1. Right-click Tab1, and click Rename on the shortcut menu. Type Red in the

Caption box, and then click OK.

5. Click Tab2 to select it. Right-click Tab2, and click Rename on the shortcut menu. Type Green in the Caption box, and then click OK.

6. With the second tab still selected, right-click Green, and click New Page on the shortcut menu.

The Visual Basic Editor inserts a third Tab.

7. Right-click Tab3, and click Rename on the shortcut menu. Type Blue in the Caption box, and then click OK.

8. Click Red and cancel the selection of the Tab control by clicking on the TabStrip container.

9. Add the following controls to the TabStrip container with the listed property setting:

MsgBox TabStrip1.SelectedItem.Caption

TabStrip1.Value=2

Control Type Property Value ---------------------------------------------------------- Image Name imgColor BackColor&H000000FF& CommandButton Name cmdOK Caption OK CommandButton Name cmdCancel Caption Cancel

Page 3: How to Use the TabStrip Control in a UserForm

10. Press F7 to view the Code window for the form.

11. Type the following event procedures for the form in the Code window:

12. With the insertion point in the procedure ShowForm, press F5 to run the macro.

For more information about the TabStrip control, follow these steps:

1. Create a TabStrip control on a form.

2. Select the TabStrip control and press F1.

The "TabStrip Control" topic in the "Microsoft Forms Reference" Help file appears.

Article ID: 155009 - Last Review: October 11, 2006 - Revision: 2.2

APPLIES TO

Microsoft Excel 97 Standard EditionMicrosoft Excel 98 for Macintosh

Keywords: kbdtacode kbprogramming KB155009

Retired KB Content DisclaimerThis article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.

&H000000FF& CommandButton Name cmdOK Caption OK CommandButton Name cmdCancel Caption Cancel

Private Sub tbsColor_Change() ' This procedure runs when the TabStrip control named tbsColor ' changes. This procedure willchange the color of the image ' control based on which tab the user selects. Dim i As Integer i = tbsColor.SelectedItem.IndexSelect Case i Case 0 ' First tab selected, change color of image to red. imgColor.BackColor = RGB(255, 0, 0) Case 1 ' Secondtab selected, change color of image to green. imgColor.BackColor = RGB(0, 255, 0) Case 2 ' Third tab selected, change color ofimage to blue. imgColor.BackColor = RGB(0, 0, 255) End Select End Sub Private Sub cmdCancel_Click() ' This procedure will runwhen the command button cmdCancel is ' clicked. This procedure unloads the form. Unload Me End Sub Private Sub cmdOK_Click() 'This procedure will run when the command button cmdOK is clicked. ' This procedure displays a message indicating which tab is' selected and then unloads the form. MsgBox "You selected " & tbsColor.SelectedItem.Caption Unload Me End Sub

REFERENCES

Properties