英文:
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 = ""
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:
'your code...
For Each ctrl In ActiveSheet.OLEObjects
ctrl.Object.Value = ""
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论