2013-12-17 125 views
1

我試圖強調用戶選擇它時從activeX控件的選項按鈕。我決定在選中時顯示陰影,然後在用戶選擇其他選項按鈕時隱藏陰影。第一個過程正在運行,而即使我選擇了其他按鈕,陰影也不能被刪除。我的VBA代碼如下所示:從Excel 2010中的ActiveX選項按鈕中刪除陰影VBA

Private Sub OptionButton1_Click() 

OptionButton1.Shadow = False 

If OptionButton1.Value = True Then 
OptionButton1.Shadow = True 

Else 
OptionButton1.Shadow = False 

End If 

End Sub 

任何人都可以請幫我解決這個問題嗎?

+0

你在其他按鈕從OptionButton1去除陰影有代碼? – JosieP

回答

0

爲此,您必須創建一個需要從所有選項按鈕中調用的子。這個共同的子將只刪除所有選項按鈕的陰影。這裏我以3個選項按鈕爲例。

Option Explicit 

Private Sub OptionButton1_Click() 
    RemoveShadow 

    If OptionButton1.Value = True Then _ 
    OptionButton1.Shadow = True 
End Sub 

Private Sub OptionButton2_Click() 
    RemoveShadow 

    If OptionButton2.Value = True Then _ 
    OptionButton2.Shadow = True 
End Sub 

Private Sub OptionButton3_Click() 
    RemoveShadow 

    If OptionButton3.Value = True Then _ 
    OptionButton3.Shadow = True 
End Sub 

Sub RemoveShadow() 
    Dim objOpt As OLEObject 

    With ActiveSheet 
     For Each objOpt In .OLEObjects 
      If TypeName(objOpt.Object) = "OptionButton" Then 
       objOpt.Shadow = False 
      End If 
     Next 
    End With 
End Sub 
+0

它適合我,非常感謝你! – user1805430

+0

很高興有幫助:) –

1

在表單的按鈕情況下,你可以使用

Sub RemoveFormsButtonShadows() 
    'A.Leine 21/10/2015 
    For Each Button In ActiveSheet.Shapes 
     Button.Select 
     Selection.ShapeRange.Shadow.Visible = False 
    Next Button 
End Sub