davis1118
03-25-2018, 03:51 PM
I'm trying to create shapes that will be applied to a sheet from a userform, and be populated with the userform data. I am successfully creating the rounded rectangle shape, placing the shape, sizing the shape and changing the text in the shape. But for whatever reason the fill color does not change from the default color setting. Awhile back I set the default shape to a shape with a green fill color. Now I am trying to create a shape with VBA and I want to fill it with a blue color, but the shape is always the default green color. Is it an issue if I set the default color different from the original Excel default? Or am I missing something simple in the code? I've sadly wasted half a day with this little issue, and once again need help.
Sub AddButtons()
Dim Names As String
Dim Captions As String
Dim LeftPos As Long
Dim newBtn As Shape
shtnm = ThisWorkbook.ActiveSheet.Name
With ThisWorkbook.Sheets(shtnm)
Names = "Btn1"
Captions = ENGForm.DocName1.Value
LeftPos = 165
Set newBtn = .Shapes.AddShape(msoShapeRoundedRectangle, Left:=LeftPos, Top:=225.5, Width:=105.75, Height:=52.5)
With newBtn
.Name = Names
.TextFrame.Characters.Text = Captions
.Fill.BackColor.RGB = RGB(136, 182, 224)
End With
End With
End Sub
Sub AddButtons()
Dim Names As String
Dim Captions As String
Dim LeftPos As Long
Dim newBtn As Shape
shtnm = ThisWorkbook.ActiveSheet.Name
With ThisWorkbook.Sheets(shtnm)
Names = "Btn1"
Captions = ENGForm.DocName1.Value
LeftPos = 165
Set newBtn = .Shapes.AddShape(msoShapeRoundedRectangle, Left:=LeftPos, Top:=225.5, Width:=105.75, Height:=52.5)
With newBtn
.Name = Names
.TextFrame.Characters.Text = Captions
.Fill.BackColor.RGB = RGB(136, 182, 224)
End With
End With
End Sub