gpt4 book ai didi

检查表单控件类型时 VBA 运行时错误 1004 “Application-defined or Object-defined error”

转载 作者:行者123 更新时间:2023-12-04 21:53:25 27 4
gpt4 key购买 nike

我希望你能帮助我。我已经没有成功地寻找解决方案。在 Excel 表中,我尝试使用宏来计算激活的复选框。

Option Explicit
Public Sub Count_CheckBoxes()
Dim counter As Integer
Dim shpBox As Shape
With Tabelle1
For Each shpBox In .Shapes
With shpBox
If .FormControlType = xlCheckBox Then
If .ControlFormat.Value = xlOn Then
counter = counter + 1
End If
End If
End With
Next
.Cells(29, 3).Value = counter
End With
End Sub

当我尝试运行此代码时,我收到运行时错误 1004 “Application-defined or Object-defined error”,指示行 If .FormControlType = xlCheckBox Then .

我的 excel 文件有几张工作表,包括工作簿在内的所有工作表都不 protected 。我没有宏方面的技能,我认为这是一个非常简单的错误......但是我找不到它。

谢谢您的帮助。

最佳答案

在询问 .FormControlType 之前确保形状是表单控件:

If shpBox.Type = msoFormControl Then

关于检查表单控件类型时 VBA 运行时错误 1004 “Application-defined or Object-defined error”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49951111/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com