ActiveX Optionbutton BackStyle = Transparent setting

knowak1968

New Member
Joined
Mar 18, 2020
Messages
5
Office Version
  1. 365
Platform
  1. Windows
I have an odd issue i was hoping someone can help me with. I am generating Option Buttons in code and I am unable to set the Backstyle of the object to Transparent. When i change the Backstyle Property of the code generated Optionbutton to Transparent in the Properties Window (in the VB Editor), it wont go to transparent. However if i manually make an Optionbutton with the Insert>ActiveX Controls>OptionButton, i can successfully toggle between Transparent and Opaque. Is there some sort of hidden property Im not aware of? Perhaps I'm using the wrong ClassType?

Here is my code which simply places an Optionbutton in the ActiveCell of the ActiveSheet:

Private Sub AddOptionButton()


Dim sht As Worksheet
Dim OptBtn As OLEObject
Dim rng As Range

Set sht = ActiveSheet
Set rng = ActiveCell


With sht
Set OptBtn = .OLEObjects.Add(ClassType:="Forms.Optionbutton.1")
End With


OptBtn.Object.Caption = "Click Me"
OptBtn.Name = "ButtonName"
'Optbtn.Object.BackStyle = fmBackStyleTransparent (here is where i was trying to set it in code - but didnt work anyway)


End Sub


Try to change this object's BackStyle property to fmBackStyleTransparent (or 0) and it will remain Opaque.
 

Some videos you may like

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,253
Office Version
  1. 365
Platform
  1. Windows
Why not use a Form Control option button instead?
 

knowak1968

New Member
Joined
Mar 18, 2020
Messages
5
Office Version
  1. 365
Platform
  1. Windows
Why not use a Form Control option button instead?
I may, but I still want to know why this isnt working. I may end up needing to create an event handler class because my option buttons will be dynamically generated. What i have shown is just an example sub for this thread to demonstrate the transparency issue...
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,253
Office Version
  1. 365
Platform
  1. Windows
I cannot give you a reason, why the backstyle doesn't work, I just know it doesn't. Likewise, if you apply a backcolor to one that's create by code, you get a slight border which you don't get with one added manually.
ActiveX controls a notoriously flaky, which is why I tend not to use them.
 

knowak1968

New Member
Joined
Mar 18, 2020
Messages
5
Office Version
  1. 365
Platform
  1. Windows
I cannot give you a reason, why the backstyle doesn't work, I just know it doesn't. Likewise, if you apply a backcolor to one that's create by code, you get a slight border which you don't get with one added manually.
ActiveX controls a notoriously flaky, which is why I tend not to use them.
Very interesting. That answers a lot. I will have consider Form Controls then. Thanks!
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,253
Office Version
  1. 365
Platform
  1. Windows
You're welcome & thanks for the feedback.
 

Watch MrExcel Video

Forum statistics

Threads
1,126,998
Messages
5,622,097
Members
415,876
Latest member
csibonga2k17

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
Top