Parent プロパティの例

次の例では、 Parent プロパティを使用して、特定のコントロールを含むコントロールまたはフォームを参照します。

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

  • 2 つのラベル ( Label ) コントロール (Label1 と Label2)
  • CommandButton1 と命名された CommandButton
  • 任意のコントロール
Dim MyControl As Object 
Dim MyParent As Object 
Dim ControlsIndex As Integer 
 
Private Sub UserForm_Initialize() 
 ControlsIndex = 0 
 CommandButton1.Caption = "Get Control and Parent" 
 CommandButton1.AutoSize = True 
 CommandButton1.WordWrap = True 
End Sub 
 
Private Sub CommandButton1_Click() 
 'Process Controls collection for UserForm 
 Set MyControl = Controls.Item(ControlsIndex) 
 Set MyParent = MyControl.Parent 
 Label1.Caption = MyControl.Name 
 Label2.Caption = MyParent.Name 
 
 'Prepare index for next control on Userform 
 ControlsIndex = ControlsIndex + 1 
 If ControlsIndex >= Controls.Count Then 
 ControlsIndex = 0 
 End If 
End Sub

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

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