SelectedItem 属性、TabStrip 控件、Tab 对象、Tabs 集合示例SelectedItem property, TabStrip control, Tab object, Tabs collection example

下面的示例通过几种方式访问 TabStrip 中单个选项卡:The following example accesses an individual tab of a TabStrip in several ways:

  • 使用数字索引访问 Tabs 集合。Using the Tabs collection with a numeric index.

  • Tabs 集合与字符串索引结合使用。Using the Tabs collection with a string index.

  • Tabs集合与**Item** 方法结合使用。Using the Tabs collection with the Item method.

  • 使用单个 Tab 的名称。Using the name of the individual Tab.

  • 使用 SelectedItem 属性。Using the SelectedItem property.

若要使用此示例,请将此示例代码复制到窗体的声明部分。To use this example, copy this sample code to the Declarations portion of a form. 确保此窗体包含名为 TabStrip1 的 TabStripMake sure that the form contains a TabStrip named TabStrip1.

Private Sub UserForm_Initialize() 
 Dim TabName As String 
 For i = 0 To TabStrip1.Count - 1 
 'Using index (numeric or string) 
 MsgBox "TabStrip1.Tabs(i).Caption = " _ 
 & TabStrip1.Tabs(i).Caption 
 MsgBox "TabStrip1.Tabs.Item(i).Caption = " _ 
 & TabStrip1.Tabs.Item(i).Caption 
 TabName = TabStrip1.Tabs(i).Name 
 MsgBox "TabName = " & TabName 
 MsgBox "TabStrip1.Tabs(TabName).Caption = " _ 
 & TabStrip1.Tabs(TabName).Caption 
 MsgBox "TabStrip1.Tabs.Item(TabName)_ 
 .Caption = " _ 
 & TabStrip1.Tabs.Item(TabName).Caption 
 'Use Tab object without referring to Tabs 
 If i = 0 Then 
 MsgBox "TabStrip1.Tab1.Caption = " _ 
 & TabStrip1.Tab1.Caption 
 ElseIf i = 1 Then 
 MsgBox "TabStrip1.Tab2.Caption = " _ 
 & TabStrip1.Tab2.Caption 
 'Use SelectedItem Property 
 TabStrip1.Value = i 
 MsgBox "TabStrip1.SelectedItem.Caption = " _ 
 & TabStrip1.SelectedItem.Caption 
 Next i 
End Sub

支持和反馈Support and feedback

有关于 Office VBA 或本文档的疑问或反馈?Have questions or feedback about Office VBA or this documentation? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.