2015-10-18 154 views
2

我正在創建一個宏來清除表單中的單元格和所有複選框,但它僅清除第一個組框中的複選框(並且保留所有其他複選框打勾)。我的代碼:清除所有複選框

Sub clearcheck() 
ActiveSheet.CheckBoxes.Value = False 

Range("D4:E4").Select 

    Selection.ClearContents 
    ActiveSheet.Shapes.Range(Array("Label 61")).Select 
    Range("H4:I4").Select 
    Selection.ClearContents 
    Range("M4:N4").Select 
    Selection.ClearContents 

End Sub 

Screenshot

 http://i.stack.imgur.com/ddkxF.png

誰能幫我用我的代碼?

回答

1

您可能正面臨着將FormControls與ActiveX控件混合的典型問題。試試這個代碼,讓我知道它是否有效:

Public Sub UncheckAll() 

On Error Resume Next 
For Each x In Worksheets("Sheet2").Shapes 
    Select Case x.Type 
    Case 8 
     Debug.Print x.Name & " is a FormControl" 
     x.OLEFormat.Object.Value = False 
    Case 12 
     Debug.Print x.Name & " is an ActiveX Control" 
     Worksheets("Sheet2").OLEObjects(x.Name).Object.Value = False 
    Case Else 
     Debug.Print x.Name & " is neither" 
    End Select 
Next x 
On Error GoTo 0 

End Sub