重置所有对活动工作表的控制。

huangapple go评论52阅读模式
英文:

Reset all control on ActiveSheet

问题

我需要将Activesheet上的所有控件(不是用户窗体)重置为null。
我尝试使用OLEObject或Controls进行循环,但出现了以下错误:

运行时错误 '438':对象不支持此属性或方法。

在这行 For Each ctrl In ActiveSheet.OLEObject。我甚至尝试使用不推荐的 On Error Resume Next,但没有帮助。
Activesheet只包含两个TextBox(ActiveX)和一个ComboBox(ActiveX)

Sub Reset_All_control_on_ActiveSheet()
    Dim ctrl As OLEObject
     For Each ctrl In ActiveSheet.OLEObject
        ctrl.Value = ""
     Next
End Sub
英文:

I need to reset all controls on Activesheet (not a userform) to null. <br>
I tried to loop using ( OLEObject or Controls) but I got :

> Run-time error '438': Object doesn't support this property or method.

At this line For Each ctrl In ActiveSheet.OLEObject . <br> I even tried to use the not recommended On Error Resume Next, But it did not help. <br>
The activesheet only contains two TextBox (ActiveX) and one ComboBox (ActiveX)

Sub Reset_All_control_on_ActiveSheet()
    Dim ctrl As OLEObject
     For Each ctrl In ActiveSheet.OLEObject
        ctrl.Value = &quot;&quot;
     Next
End Sub

答案1

得分: 1

Please, try the next way:

If you intend to place other oleObjects (in the future) you can condition the code to run only if the objects are of type TextBox or ComboBox:
```Si vous avez l'intention de placer d'autres oleObjects (à l'avenir), vous pouvez conditionner le code à s'exécuter uniquement si les objets sont de type TextBox ou ComboBox :


<details>
<summary>英文:</summary>

Please, try the next way:
 &#39;your code...
 For Each ctrl In ActiveSheet.OLEObjects
    ctrl.Object.Value = &quot;&quot;
 Next
If you intent to place other oleObjects (in the future) you can condition the code to run only if the objects are of type `TextBox` of `ComboBox`:

For Each ctrl In ActiveSheet.OLEObjects
If TypeOf ctrl.Object Is MSForms.TextBox Or _
TypeOf ctrl.Object Is MSForms.ComboBox Then 'to exclude other types...
ctrl.Object.Value = ""
End If
Next

huangapple
  • 本文由 发表于 2023年2月8日 17:20:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/75383570.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定