PDA

View Full Version : INSERT TEXT AND FORMAT AUTOSHAPE



DeanP
12-08-2018, 08:03 PM
In my worksheet I've added a shape and placed text in the shape. Now I want to format the shape by changing the fill and font. I cannot find any information on how to continue with the code for doing that from where I ended the last.
At help wold be appreciated.

I have this code

#Sub AddRectangle()
Dim shp As Shapes
Set shp = ActiveSheet.Shapes
With shp
With .AddShape(msoShapeRoundedRectangle, 112, 135, 255, 23).TextFrame
.Characters.Text = "The default period has been changed to September 2018"
.HorizontalAlignment = xlHAlignLeft
.VerticalAlignment = xlVAlignCenter
End With
End With
Set shp = Nothing
End Sub#

What now? Where/how do I start the next thing - change the fill?

Kenneth Hobs
12-08-2018, 08:58 PM
Sub AddRectangle()
Dim s As Shape
Set s = ActiveSheet.Shapes.AddShape(msoShapeRoundedRectangle, 112, 135, 255, 23)
With s.TextFrame
.Characters.Text = "The default period has been changed to September 2018"
.Characters.Font.Color = vbRed
s.Fill.ForeColor.RGB = vbYellow
.HorizontalAlignment = xlHAlignLeft
.VerticalAlignment = xlVAlignCenter
End With
End Sub