2016-07-24 2 views
1

일부 코드를 다시 작성하고 생각했지만 제대로 실행하려면 구문을 올바르게 처리 할 수 ​​없습니다. 나는 for 루프를 사용하여 commandbutton의 배열을 생성하고 가시성을 제어하고자한다. 루프에서 작업중인 CommandButton 번호를 정의하려면 구문을 사용하는 데 도움이 필요합니다. 예를 들어, CommandButton1, CommandButton2 등VBA Variable as CommandButton #

Public Sub LoadLots(sName As String, streamLots() As String) 
    Label1.Caption = sName 
    For o = 1 To 9 
     If streamLots(o) <> "" Then 
      CommandButton& o &.Caption = streamLots(o) 
      CommandButton& o & .Visable = True 
     Else 
      CommandButton& o & .Visable = False 
     End If 
    Next 
End Sub 
+2

'Activesheet.Shapes ("있는 명령"& O) .Caption' ... 또한'Visable'이어야 Visible' I '가 추가되어야 –

+0

는이 버튼 폼이다. – Flibertyjibbet

+0

동일한 원칙이지만 아래 답변도 있습니다. –

답변

2

명령 단추를 이름으로 참조하려면 Userform.Controls 컬렉션을 사용하십시오.

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

완벽한, 감사합니다. – Flibertyjibbet

+0

기꺼이 도와 드릴 수있었습니다. 수표를 가져 주셔서 감사합니다. –