2017-06-13 41 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。我改编了一下我的代码。请问您有关于形状,选项按钮等的任何教程吗?我完全吮吸在这! –