2017-12-05 1 views
1

사용자가 일단 클릭하면 내 시트 1에있는 버튼을 비활성화하려고합니다. 나는 몇 가지 오래된 Stackoverflow answers하지만 dosent 내 기대로 일했다.VBA : 첫 번째 클릭 후 Excel에서 버튼 사용 안 함

코드 :

Sub Button2_Click() 

    Call FindADate 

    Dim myshape As Shape: Set myshape = ThisWorkbook.Worksheets("Sheet1").Shapes("Button 2") 
    With myshape 
     .ControlFormat.Enabled = False   '---> Disable the button 
     .TextFrame.Characters.Font.ColorIndex = 15 '---> Grey out button label 
    End With 
End Sub 

실제로 버튼이 비활성화되어 있지만 사용자가 또 다시 클릭하고 내 코드를 실행하는 느낌을주는 버튼을 회색으로.

1 클릭 후 버튼을 사용할 수 없도록하는 해결책을 알려주십시오. 버튼을 한 번 클릭 한 다음 다시 닫으면 Excel이 다시 열립니다. (MS Office Professional Plus 2013을 사용 중입니다.)

미리 감사드립니다.

+0

이유가 클릭 된 것을 기억하는 변수를 유지하지 충분해야한다인가? –

+0

감사합니다. @ Meaden은 저에게 어떻게하는지 보여 주시겠습니까 –

답변

2
Option Explicit 

Sub Button2_Click() 
    Static vDisable As Variant 
    If IsEmpty(vDisable) Then 

     Call FindADate 

     Dim myshape As Shape: Set myshape = ThisWorkbook.Worksheets("Sheet1").Shapes("Button 2") 
     With myshape 
      .ControlFormat.Enabled = False   '---> Disable the button 
      .TextFrame.Characters.Font.ColorIndex = 15 '---> Grey out button label 
     End With 
     vDisable = True 
    End If 
End Sub 
0

희미한 라인 그냥 쓰기 후 :

if myshape.TextFrame.Characters.Font.ColorIndex = 15 then exit sub