knowak1968
New Member
- Joined
- Mar 18, 2020
- Messages
- 5
- Office Version
- 365
- Platform
- 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.
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.