How To Use The TabStrip Control in A UserForm
How To Use The TabStrip Control in A UserForm
Article ID: 155009 - View products that this article applies to.
SUMMARY
This article explains how to use the TabStrip control in a UserForm and provides a Microsoft Visual Basic for Applications example.
MORE INFORMATION
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.
1. 2. 3. 4.
Click the UserForm to activate it. On the View menu, click Toolbox to display the toolbox. Click the TabStrip control button. Draw the TabStrip control on the form.
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.
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: C o n t r o lT y p eP r o p e r t yV a l u e-I m a g eN a m ei m g C o l o rB a c k C o l o r & H 0 0 0 0 0 0 F F &C o m m a n d B u t t o nN a m ec m d O KC a p t i o nO KC o m m a n d B u t t o nN a m ec m d C a n c e lC a p t i o nC a n c e l
& H 0 0 0 0 0 0 F F &C o m m a n d B u t t o nN a m ec m d O KC a p t i o nO KC o m m a n d B u t t o nN a m ec m d C a n c e lC a p t i o nC a n c e l 10. Press F7 to view the Code window for the form. 11. Type the following event procedures for the form in the Code window: P r i v a t eS u bt b s C o l o r _ C h a n g e ( )'T h i sp r o c e d u r er u n sw h e nt h eT a b S t r i pc o n t r o ln a m e dt b s C o l o r'c h a n g e s .T h i sp r o c e d u r ew i l l c h a n g et h ec o l o ro ft h ei m a g e'c o n t r o lb a s e do nw h i c ht a bt h eu s e rs e l e c t s .D i miA sI n t e g e ri=t b s C o l o r . S e l e c t e d I t e m . I n d e x S e l e c tC a s eiC a s e0'F i r s tt a bs e l e c t e d ,c h a n g ec o l o ro fi m a g et or e d .i m g C o l o r . B a c k C o l o r=R G B ( 2 5 5 ,0 ,0 )C a s e1'S e c o n d t a bs e l e c t e d ,c h a n g ec o l o ro fi m a g et og r e e n .i m g C o l o r . B a c k C o l o r=R G B ( 0 ,2 5 5 ,0 )C a s e2'T h i r dt a bs e l e c t e d ,c h a n g ec o l o ro f i m a g et ob l u e .i m g C o l o r . B a c k C o l o r=R G B ( 0 ,0 ,2 5 5 )E n dS e l e c tE n dS u bP r i v a t eS u bc m d C a n c e l _ C l i c k ( )'T h i sp r o c e d u r ew i l lr u n w h e nt h ec o m m a n db u t t o nc m d C a n c e li s'c l i c k e d .T h i sp r o c e d u r eu n l o a d st h ef o r m .U n l o a dM eE n dS u bP r i v a t eS u bc m d O K _ C l i c k ( )' T h i sp r o c e d u r ew i l lr u nw h e nt h ec o m m a n db u t t o nc m d O Ki sc l i c k e d .'T h i sp r o c e d u r ed i s p l a y sam e s s a g ei n d i c a t i n gw h i c ht a bi s 's e l e c t e da n dt h e nu n l o a d st h ef o r m .M s g B o x" Y o us e l e c t e d"&t b s C o l o r . S e l e c t e d I t e m . C a p t i o nU n l o a dM eE n dS u b 12. With the insertion point in the procedure ShowForm, press F5 to run the macro.
REFERENCES
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.
Properties
Article ID: 155009 - Last Review: October 11, 2006 - Revision: 2.2 APPLIES TO
Microsoft Excel 97 Standard Edition Microsoft Excel 98 for Macintosh