简体   繁体   English

如何从Excel VBA中的工作表中获取ActiveX活动控件

[英]How To Get the ActiveX Active Control from a Worksheet in Excel VBA

I have a spreadsheet with some ActiveX controls like combo boxes, text boxes, etc... on the Change event of each control there's function that receives the ActiveSheet as parameter. 我有一个包含一些ActiveX控件(如组合框,文本框等)的电子表格,在每个控件的Change事件上,都有将ActiveSheet作为参数接收的函数。 this funtion is in the MainModule. 这个功能在MainModule中。 what I need is to get the active control from this ActiveSheet having in mind that this control is an ActiveX control. 我需要的是从该ActiveSheet获取活动控件,同时要记住该控件是ActiveX控件。

for instance, everytime I do changes in the combo boxes, text boxes, etc... I call this function and, through the ActiveSheet (passed as parameter) I can know if I changed a combo box or a text box or a list box, etc... 例如,每次我在组合框,文本框等中进行更改时,我都会调用此函数,并且通过ActiveSheet(作为参数传递),我可以知道是否更改了组合框,文本框或列表框等

thanks in advance. 提前致谢。

Insert a activeX checkbox control and name it "chkboxFoo" via Properties Window. 插入一个activeX复选框控件,并通过“属性”窗口将其命名为“ chkboxFoo”。

Dim IsFooChecked As Boolean : IsFooChecked = False
IsFooChecked = ActiveSheet.OLEObjects("chkboxFoo").Object.Value
If IsFooChecked Then
    MsgBox "BarMsg! You made it."
Else
    MsgBox "Try to check the checkbox then execute the program. " & _
           "You shall see a msgbox says BarMsg."

Reference: http://blogs.infoextract.in/worksheet-controls-automation-using-vba/ 参考: http : //blogs.infoextract.in/worksheet-controls-automation-using-vba/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM