How to select TextBox Using VBA
How to select TextBox Using VBA. I want to make changes for those Textboxes which i have selected manually to change their font, backcolor.
Set s = ws.Shapes("").Selected Shape
Sub TextBox()
Dim wb As Workbook
Dim ws As Worksheet
Dim s As Shape
Set ws = ActiveSheet
Set s = ws.Shapes("TextBox 7") ' Here i want to add one thing that is it should work for selected textbox manually
s.TextFrame2.TextRange.Font.Fill.ForeColor.RGB = RGB(0, 0, 0)
s.TextFrame2.TextRange.Font.Bold = msoTrue
s.Fill.ForeColor.RGB = RGB(255, 192, 0)
End Sub
Solution 1:
The code can be simplified by using the ShapeRange property of the Selection object that returns all the shapes in the selection.
The following example sets the fill foreground color for all the shapes in the selection in window one, assuming that there's at least one shape in the selection.
Windows(1).Selection.ShapeRange.Fill.ForeColor.RGB = RGB(255, 0, 255)
In your code, you could just set:
Set s = Windows(1).Selection.ShapeRange