2016-05-29 16 views

答えて

0

はい、それはあなたが任意のイベントサブ/ eventhandにそれを置くことができますもちろんのインスタンス

Private Sub CommandButton1_Click() 
    ReDim myArray(0 To Me.Controls.count - 1) As MSForms.Label '<~~ declare this array with the maximum possible dimensions 
    Dim lblCounter As Long 
    Dim ctrl As MSForms.Control 

    With Me '<~~ this refers to the UserForm object of which code pane you placed this code into 
     For Each ctrl In .Controls '<~~ loop through UserForm controls 
      If TypeName(ctrl) = "Label" Then '<~~ if you find a "Label"... 
       Set myArray(lblCounter) = ctrl '<~~ ... then store it in your array... 
       lblCount = lblCounter + 1 '<~~ ... and update the label counter 
      End If 
     Next ctrl 
    End With 
    If lblCounter > 0 Then ReDim Preserve myArray(0 To lblCounter - 1) '<~~ if you actually found at least one label, then redim your array with proper dimensions 
End Sub 

ため

ですあなたのUserform Controlsコレクション

+0

にアクセスできるようになりました。 – 5kong

+0

あなたはようこそ – user3598756

関連する問題