- Back to Home »
- VBA »
- [VBA] ActiveX Controls
Thursday, December 5, 2019
1. Create and set/get value to control
Access ActiveX Controls by:
Worksheet("sheetname").ComponentName
Ex:
Sub main()
Debug.Print ActiveSheet.TextBoxName.Value
'or
Debug.Print ActiveSheet.OLEObjects("TextBoxName").Object.Value
End Sub
For how to set/get component value, reference to UserForm
2. Get type of ActiveX control
Sub getTypeControl()
Dim ws As Worksheet
Dim oleob As OLEObject
Set ws = ActiveSheet
For Each oleob In ws.OLEObjects
If TypeName(oleob.Object) = "TextBox" Then 'if type: TextBox
oleob.Object.Value = "hihi haha"
End If
Next
End Sub