2017-06-13 39 views
0

我想取消激活我的選項按鈕,但由於我已將它們分組在一起,因此我的代碼將不再工作。VBA - For Each,OptionButtons和Groups

到目前爲止,我有這樣的:

Sub Clean_sheet() 
Dim Ws as Worksheet 
Dim optBtn As OptionButton 
Dim m As Byte 

Application.Calculation = xlCalculationManual 
Application.ScreenUpdating = False 

Set Ws = ThisWorkbook.Sheets("Externe") 

    For Each optBtn In Ws.OptionButtons 
     optBtn.Value = -4146 
    Next 

Application.Calculation = xlCalculationAutomatic 
Application.ScreenUpdating = True 
End Sub 

它只是跳過部分「對於每個optBtn ......」。我不使用activexControls。

我的組是這樣的:

enter image description here

enter image description here

I've already been helped但因爲我我的組合形式它不工作:( 預先感謝您的幫助

回答

1

以下代碼將取消選擇組「GPE_M1」中的所有選項:

Dim Group_Frame As Shape 
Dim Group_Item As Shape 

    Set Group_Frame = ws.Shapes("GPE_M1") 'top frame 

    For Each Group_Item In Group_Frame.GroupItems 
     If Group_Item.FormControlType = xlOptionButton Then 
      Group_Item.ControlFormat.Value = -4146 
     End if 
    Next Group_Item 
+0

非常感謝RADO。我改編了一下我的代碼。請問您有關於形狀,選項按鈕等的任何教程嗎?我完全吮吸在這! –