I want to create a textbox with a yellow background and that is sized based on my current selected cell range.
I found a solution for the cell range - but can't figure out how to make the textbox it creates not white. Below is the code I currently have:
Sub TextBox2Selection()
If TypeName(Selection) = "Range" Then
With Selection
ActiveSheet.Shapes.AddTextbox _
msoTextOrientationHorizontal, .Left, _
.Top, .Width, .Height
End With
End If
End Sub
I want to create a textbox with a yellow background and that is sized based on my current selected cell range.
I found a solution for the cell range - but can't figure out how to make the textbox it creates not white. Below is the code I currently have:
Sub TextBox2Selection()
If TypeName(Selection) = "Range" Then
With Selection
ActiveSheet.Shapes.AddTextbox _
msoTextOrientationHorizontal, .Left, _
.Top, .Width, .Height
End With
End If
End Sub
Share
Improve this question
edited Mar 18 at 20:12
BigBen
50.2k7 gold badges28 silver badges44 bronze badges
asked Mar 18 at 20:07
user29988185user29988185
211 silver badge2 bronze badges
1 Answer
Reset to default 2For example:
Sub TextBox2Selection()
Dim sel As Object
Set sel = Selection
If TypeName(sel) <> "Range" Then Exit Sub 'exit if a range is not selected
' `AddTextbox` returns a reference to the added shape
With ActiveSheet.Shapes.AddTextbox(msoTextOrientationHorizontal, _
sel.Left, sel.Top, sel.Width, sel.Height)
.Fill.Visible = msoTrue
.Fill.ForeColor.RGB = RGB(255, 255, 0) 'or vbYellow
End With
End Sub