简体   繁体   中英

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. this funtion is in the MainModule. what I need is to get the active control from this ActiveSheet having in mind that this control is an ActiveX control.

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...

thanks in advance.

Insert a activeX checkbox control and name it "chkboxFoo" via Properties Window.

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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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