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.
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Why not use a Form Control option button instead?
 
Upvote 0
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...
 
Upvote 0
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.
 
Upvote 0
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!
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,213,544
Messages
6,114,249
Members
448,556
Latest member
peterhess2002

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