Set checkbox background transparent - vba

I can't for the life of me find how to set a form control checkbox background to transparent
Dim cb As CheckBox
For Each cb In ActiveSheet.CheckBoxes
cb.Value = -4146
cb.Interior.Color = ???
Next cb
To be clear I'm talking about a Forms checkbox on a worksheet, not on a form and not an ActiveX checkbox (Developer menu > Insert > Form Controls).
I recorded a macro and got this but I'm wondering if there's a way to do it via the Checkbox object rather than use the Shape object. Even a link to the MSDN Dev page for a Form Controls checkbox would help as I can't find it!
ActiveSheet.Shapes("cb1_1").Fill.Visible = msoFalse

cb.Interior.ColorIndex = xlNone

Related

Edit Form Control Label Caption on VBA

Trying to edit the text of a form control label named lblsearchreminder and make sure that the font is Arial and size 20. I am pulling the edited text from an ActiveX textbox1 and trying to make that the caption of the label. If anyone has any insight I would greatly appreciate it.
Sub btnAltCustomSearch_Click()
Dim strTextBox As String
If Worksheets("User Interface").OLEObjects("TextBox1").Object.Value = "" Then
ErrorX.Show
Else
strTextBox = Worksheets("User Interface").OLEObjects("TextBox1").Object.Value
Worksheets("Muscle Wasting Database").Shapes("lblsearchreminder") = vbCrLf & "Disease: All" & vbCrLf & vbCrLf & "Keyword: " & strTextBox
lblsearchreminder.Object.Characters.Text = "Arial"
lblsearchreminder.Object.Font.Size = 20
End If
End Sub
Yes the textbox1 is an ActiveX textbox control, but I will ideally use a Form Control label. So I am trying to pull the typing from the ActiveX textbox and use it in the Form Control label – Thor Nagel 3 hours ago
Unfortunately you can't manipulate the font-size/name, color or style of a Form Control Label. If you notice the formatting items have been "grayed out" in the Font group on the Excel Ribbon.
To set a Text is easy
Dim lblsearchreminder As Shape
Set lblsearchreminder = Sheet1.Shapes("Label 1")
lblsearchreminder.TextFrame.Characters.Text = "Hello"
But you cannot do (Even though Intellisense allows it)
lblsearchreminder.TextFrame.Characters.Font.Name = "Arial"
or
lblsearchreminder.TextFrame2.TextRange.Characters.Font.Name = "Arial"
I would recommend using a TextBox shape or an ActiveX Label instead.
Similarly you cannot change the font using
lblsearchreminder.TextFrame.Characters.Font.Size= 20
I don't think you're using a Form Control. TextBox1 would be the default name for an ActiveX control, which would be coherent with using .OLEObject.Object to retrieve it.
Declare a MSForms.TextBox variable for it.
Dim box As MSForms.TextBox
Now assign it to the .OLEObject.Object:
Set box = Worksheets("User Interface").OLEObjects("TextBox1").Object
If the sheet "User Interface" exists in ThisWorkbook at compile-time, give it a code name (F4; set the (Name) property to e.g. UserInterfaceSheet) - then you can use that identifier directly, without needing to pull the worksheet from the Worksheets collection:
Set box = UserInterfaceSheet.OLEObjects("TextBox1").Object
Now you have an early-bound object reference to play with, you'll have IntelliSense to guide you. MSForms.TextBox does not have a .Characters property. It does have a .Font property though, so you can start exploring that:
So the Font property is an object of type NewFont; using the Object Browser (F2) you can browse its members:
Thus:
box.Font.Name = "Arial"
box.Font.Size = 20
Should do it.
Watch out for misleading names and prefixes: lblsearchreminder reads like you're looking at a MSForms.Label control, not a TextBox. txtSearchReminder would be more appropriate, or if you prefer control-agnostic names, SearchReminderBox works as well.
Also Error is a function from the VBA.Conversion module, that you are shadowing here.

Floating Message/Comment Box

So pretty much what I am trying to do is create a floating text box that would be on the right of the spreadsheet. When a user selects a row/cell it will then place a comment or message with details about that cell in there rather than a small little comment box.
I have tried to use the UserForm Box but its not really what I'm looking for.
Example:
User Selects Cell A4, I would like a message to read in a floating text when that cell is selected. Then if a user selects Cell B6 a different message appears in that box.
Does that makes sense?
Update:
The Following Code Shows a UserForm box when a certain cell is selected:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim Definition As String
If Intersect(Target, Range("C6:D6")) Is Nothing Then Exit Sub
Select Case Target.Row
Case 22
Definition = "Text Here"
Case 23
Definition = "Text Here Again"
End Select
UserForm1.Label1.Caption = Definition
UserForm1.Show
End Sub
I don't want to use a UserForm box as its not stationary on the Worksheet itself. I want it so a Text Box that always appears on the right hand side of the worksheet to display a set message or context when the cell is selected. It will be different then what is stored in the actual cell.
Use a Data Validation message. This type of message "pops-up" whenever you click on a cell:
You can place a Label or TextBox control directly in the worksheet - make sure it's an ActiveX control, not a Forms control - and position it dynamically using the worksheet's SelectionChange event:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
With Me.lblText
.Visible = False
Select Case Target.Row
Case 22
.Caption = "Text Here Again"
Case 23
.Caption = "Text Here Again"
Case Else
.Visible = False
Exit Sub
End Select
' Place the label to the right of the target cell
.Left = Target.Left + Target.Width
' Or place the label in the far left of the window
'.Left; =; Application.ActiveWindow.VisibleRange.Width; -; .Width
.Top = Target.Top - 0.75 ' cell borders
.Visible = True
End With
End Sub
Some hints:
Make sure the 'Placement' property of a label is 2
(XlPlacement.xlMove), as other values give you Free-Floating or
Move-and-Size.
I strongly advise you to set the background colour of the control to
&H80000004&, the predefined Windows scheme colour for menu and form
backgrounds; likewise, the foreground to &H80000008&, the menu text
colour. This ensures visibility for users who have their own colour
settings, and explicitly supports users who specify an accessible or
assistive colour scheme to ameliorate a visual impairment.
My code relies on your sheet supporting event procedures in VBA, and
on ActiveX controls. It won't work in .xlsx sheets, and it may be
blocked (or accompanied by warning dialogues) if your operating
environment has a heavy-handed security policy.
Copy-and-paste might be affected by my use of the Worksheet
SelectionChange event.
Right-Click the control in design view for the 'Format Control' menu
and uncheck 'Print Control' - if the users print the sheet, they'll
want to see the cell contents, not the label.
Also: the label's in the way of selecting and editing the control
it's sitting over. Maybe you want it 4-5mm to the right, so the users
can get the mouse into that cell. Alternately, do this in the label's
Click() or MouseMove event:
Me.lblText.Visible = False
You might draw an obvious conclusion from all this: the native comment or data validation label is a better bet than using forms and ActiveX controls.

Run Macro on All Checkboxes in Excel from a Single Checkbox

I have the following code (credit Tim Williams, here Check box to select and deselect all other check boxes in spreadsheet)
Dim CB As checkbox
For Each CB In ActiveSheet.CheckBoxes
If CB.Name <> "Expand All Checkbox" Then
CB.Value = ActiveSheet.CheckBoxes("Expand All Checkbox").Value
End If
Next CB
It works perfectly using a checkbox for selecting / deselecting all other checkboxes, but each checkbox is assigned to another macro (the same macro, simply called "checkbox"). I would like to call the "checkbox" macro as each of the other checkboxes is selected / deselected - is that possible? If so, how?!
Dim CB As checkbox
For Each CB In ActiveSheet.CheckBoxes
If CB.Name <> "Expand All Checkbox" Then
CB.Value = ActiveSheet.CheckBoxes("Expand All Checkbox").Value
Call Checkbox
End If
Next CB
Try this, I believe this is what you are trying to do.

disappearing text on mouse click in text box in powerpoint using vba

I am facing an issue with the custom textbox in a PowerPoint 2010 slide. I want to make the text that is initially there inside the textbox (say "Click to enter text") to disappear as soon as mouse is clicked on the textbox to enter some text. If this is possible through events in VBA, I would like to know which event(associated with the textbox) to capture and how to do it using VBA?
Also changing the height parameter is not having any effect in PowerPoint 2010.
here is my code that defines the textbox :
Dim sld As Slide
Set pShape = sld.Shapes.AddTextbox(msoTextOrientationHorizontal, Left:=50, Top:=50, width:=500, Height:=300)
pShape.TextFrame.TextRange = "Click to enter text"
pShape.TextFrame.TextRange.Font.Size = 14
pShape.Line.Visible = True
pShape.Line.ForeColor.RGB = RGB(0, 0, 0)
pShape.Line.DashStyle = msoLineDash
Plz help me out with this..
Thanks in advance!!!
The height is not taking because the default is to resize to fit availabl text.
Either use a shape not a textbox or reset the defaut
Set pShape = sld.Shapes.AddTextbox(msoTextOrientationHorizontal, Left:=50, Top:=50, Width:=500, Height:=300)
pShape.TextFrame.AutoSize = ppAutoSizeNone
pShape.Height = 300
Making the text disappear on click is possible but difficult. You can use the WindowSelectionChange event but this is very difficult to set up if you are not writing an addin. You would need to write a WithEvents Class module and initialise an instance. Fairly advanced!

VB - Unchecking Check Boxes in a Group Box

Currently I have 5 group boxes all filled with checkboxes, when I want to unselect all of them (for a 'clear selection' button), I use this code that I found on a forum:
For Each CheckBox In grpbox_Hiragana
CheckBox.checked = "false"
Firstly, I'm sure if this is the correct way to unselect the checkboxes, secondly the "grpbox_Hiragana" groupbox returns the following error:
Expression is of type 'System.Windows.Forms.GroupBox', which is not a collection type
If anyone could confirm this is the correct way of doing this/ help fix the error by telling me why the groupbox won't be accepted that would be great.
if you have all check box on one group box use this code :
Dim ChkBox As CheckBox = Nothing
' to unchecked all
For Each xObject As Object In Me.GroupBox1.Controls
If TypeOf xObject Is CheckBox Then
ChkBox = xObject
ChkBox.Checked = False
End If
Next
' to checked all
For Each xObject As Object In Me.GroupBox1.Controls
If TypeOf xObject Is CheckBox Then
ChkBox = xObject
ChkBox.Checked = True
End If
Next
Or you can use CheckedListBox Control.
A alternative with less lines of code is:
For Each ChkBox As CheckBox In GroupBox1.Controls
ChkBox.Checked = False
Next
Incidentally your code would have worked if you added .controls, the As CheckBox just enables the intellisense (and also ensures it is only Checkbox's that are processed) .