VBA Variable as CommandButton#

前端 未结 1 517
清歌不尽
清歌不尽 2021-01-24 09:27

I\'m rewriting some code and had a thought, but can\'t seem to get my syntax right to execute it properly. I want to use a for loop to populate an array of commandbuttons as we

相关标签:
1条回答
  • 2021-01-24 09:58

    Use the Userform.Controls collection to reference the commandbuttons by name.

    Public Sub LoadLots(sName As String, streamLots() As String)
        Dim btn As MSForms.CommandButton
        Label1.Caption = sName
        For o = 1 To 9
            Set btn = Me.Controls("CommandButton" & o)
            If streamLots(o) <> "" Then
                btn.Caption = streamLots(o)
                btn.Visible = True
            Else
               btn.Visible = False
            End If
        Next
    End Sub
    
    0 讨论(0)
提交回复
热议问题