setting properties of Activex Controls

bigt95nt

New Member
Joined
Apr 11, 2011
Messages
26
I want to use activeX controls, but am haveing problems on how to set the properties programmaticly. When using the macro recorder it records the creation of the but not the setting of the properties.

Anyone Know how to set the properties of ActiveX controls:confused:
Tony:confused:
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
You can address the properties of specific ActiveX controls on a worksheet by name via the Object property of an OLEObjects property of the worksheet. For example...

Code:
ActiveSheet.OLEObjects("TextBox1").Object.Value = "Hello"
ActiveSheet.OLEObjects("CheckBox1").Object.Value = True
ActiveSheet.OLEObjects("ListBox1").Object.ListIndex = 4

If you need to loop through the controls, Dim an object variable as OLEObject and use it in a For Each loop through the OLEObjects property of your worksheet. For example, let's say you wanted to delete all ActiveX CommandButtons on the worksheet named Sheet1...

Code:
Sub DeleteAllCommandTypeButtons()
  Dim Button As OLEObject
  With Worksheets("Sheet1")
     .Buttons.Delete
     For Each Button In .OLEObjects
       If Button.progID Like "*CommandButton*" Then Button.Delete
     Next
  End With
End Sub
 
Upvote 0
Rick - why not just set properties the same way you would if it was on a userform - if you right_click on the active X control in design mode you can set the name of the control as well as any other property from the property window. Or it can be set programatically - in the same way as on a userform. I am asking cuz I have not used it the way you propose. So I just want to understand the difference. I try not to use ActiveX controls directly on the sheet - they seem to feeeze up - so I am wondering if it is the way I set the properties - I mean not setting it as an OLE object.
 
Last edited:
Upvote 0
Rick - why not just set properties the same way you would if it was on a userform - if you right_click on the active X control in design mode you can set the name of the control as well as any other property from the property window. Or it can be set programatically - in the same way as on a userform. I am asking cuz I have not used it the way you propose. So I just want to understand the difference. I try not to use ActiveX controls directly on the sheet - they seem to feeeze up - so I am wondering if it is the way I set the properties - I mean not setting it as an OLE object.

I think the difference between the two methods is equivalent to the difference referencing a worksheet by either its (tab) Name or its CodeName... one is dynamic and the other is not. The method you use requires you to know the name of the control (which, I'll admit, is probably the majority of the time), but what if you wanted to build the name in code? Let's say you have a series of controls that are related... you could name them all the same and affix a numerical index to the end and use the OLEObjects collection to address them on the fly. For example, let's say you had 10 CheckBoxes that are related, so you name them CBox1, CBox2, etc., then you could to this in code...

Code:
' Some code that calculates and assigns the index for the CheckBox, shortened to just the assignment here
Index = 4
' Now use that calculated Index value
ActiveSheet.OLEObject("CBox" & Index).Text = SomeArray(Index)

I'm not sure why I have gotten used to using this method for all ActiveX controls, but I have a vague recollection that there were some properties I could only reach that way. It was so long ago now, however, that I am not completely sure if that was the case or not any more.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,585
Messages
6,179,704
Members
452,938
Latest member
babeneker

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top