Tag プロパティの例

次の例では、 Tag プロパティを使用して 、UserForm の各コントロールに関する追加情報を格納します。 ユーザーがコントロールをクリックし、 CommandButton をクリックします。 適切なコントロールの Tag の内容が TextBox に返されます。

この例を使用するには、以下のサンプル コードをフォームの宣言部分にコピーします。 フォームに次が含まれていることを確認してください。

  • テキスト ボックス ( TextBox ) コントロール (TextBox1)
  • CommandButton1 と命名された CommandButton
  • ScrollBar1 と命名された ScrollBar
  • コンボ ボックス ( ComboBox ) コントロール (ComboBox1)
  • マルチ ページ ( MultiPage ) コントロール (MultiPage1)
Private Sub CommandButton1_Click() 
 TextBox1.Text = ActiveControl.Tag 
End Sub 
 
Private Sub UserForm_Initialize() 
 TextBox1.Locked = True 
 TextBox1.Tag = "Display area for Tag properties." 
 TextBox1.AutoSize = True 
 
 CommandButton1.Caption = "Show Tag of Current " _ 
 & "Control." 
 CommandButton1.AutoSize = True 
 CommandButton1.WordWrap = True 
 CommandButton1.TakeFocusOnClick = False 
 CommandButton1.Tag = "Shows tag of control " _ 
 & "that has the focus." 
 
 ComboBox1.Style = fmStyleDropDownList 
 ComboBox1.Tag = "ComboBox Style is that of " _ 
 & "a ListBox." 
 
 ScrollBar1.Max = 100 
 ScrollBar1.Min = -273 
 ScrollBar1.Tag = "Max = " & ScrollBar1.Max _ 
 & " , Min = " & ScrollBar1.Min 
 
 MultiPage1.Pages.Add 
 MultiPage1.Pages.Add 
 MultiPage1.Tag = "This MultiPage has " _ 
 & MultiPage1.Pages.Count & " pages." 
End Sub

サポートとフィードバック

Office VBA またはこの説明書に関するご質問やフィードバックがありますか? サポートの受け方およびフィードバックをお寄せいただく方法のガイダンスについては、Office VBA のサポートおよびフィードバックを参照してください。