davis1118
03-26-2018, 02:00 PM
Hello,
I am in the process of trying to create multiple shapes (rounded rectangles) and place them on the worksheet. I have been able to create and place multiple shapes, but I am having trouble with creating the names and text for the shapes. The code I have below was copied from code that I was using to create multiple form control command buttons, which worked fine for those. The reason I am tying to use shapes is because I was going to use the shape as a "button" to hyperlink to external documents. The shape seems easier to insert a hyperlink directly into rather than creating a Sub that all the buttons need to point to( I haven't got to adding the hyperlink code yet, but I should be able to figure that out). The code errors on the .Name = arrNames line with "Type mismatch".
Thank you for the help.
Sub AddButtons()
Dim arrNames As Variant
Dim arrCaptions As Variant
Dim LeftPos As Long
Dim Gap As Long
Dim i As Long
Dim newBtn As Shape
shtnm = ThisWorkbook.ActiveSheet.Name
Application.ScreenUpdating = False
With ThisWorkbook.Sheets(shtnm)
arrNames = Array("EngBtn1", "EngBtn2")
arrCaptions = Array(ENGForm.DocName1.Value, ENGForm.DocName2.Value)
LeftPos = 165
Gap = 9.75
For i = 1 To 2
Set newBtn = .Shapes.AddShape(msoShapeRoundedRectangle, Left:=LeftPos, Top:=225.5, Width:=105.75, Height:=52.5)
With newBtn
.Name = arrNames
.TextFrame.Characters.Text = arrCaptions
.Fill.ForeColor.RGB = RGB(136, 182, 224)
End With
LeftPos = LeftPos + newBtn.Width + Gap
Next i
ActiveWindow.Zoom = 98
End With
Application.ScreenUpdating = True
End Sub
I am in the process of trying to create multiple shapes (rounded rectangles) and place them on the worksheet. I have been able to create and place multiple shapes, but I am having trouble with creating the names and text for the shapes. The code I have below was copied from code that I was using to create multiple form control command buttons, which worked fine for those. The reason I am tying to use shapes is because I was going to use the shape as a "button" to hyperlink to external documents. The shape seems easier to insert a hyperlink directly into rather than creating a Sub that all the buttons need to point to( I haven't got to adding the hyperlink code yet, but I should be able to figure that out). The code errors on the .Name = arrNames line with "Type mismatch".
Thank you for the help.
Sub AddButtons()
Dim arrNames As Variant
Dim arrCaptions As Variant
Dim LeftPos As Long
Dim Gap As Long
Dim i As Long
Dim newBtn As Shape
shtnm = ThisWorkbook.ActiveSheet.Name
Application.ScreenUpdating = False
With ThisWorkbook.Sheets(shtnm)
arrNames = Array("EngBtn1", "EngBtn2")
arrCaptions = Array(ENGForm.DocName1.Value, ENGForm.DocName2.Value)
LeftPos = 165
Gap = 9.75
For i = 1 To 2
Set newBtn = .Shapes.AddShape(msoShapeRoundedRectangle, Left:=LeftPos, Top:=225.5, Width:=105.75, Height:=52.5)
With newBtn
.Name = arrNames
.TextFrame.Characters.Text = arrCaptions
.Fill.ForeColor.RGB = RGB(136, 182, 224)
End With
LeftPos = LeftPos + newBtn.Width + Gap
Next i
ActiveWindow.Zoom = 98
End With
Application.ScreenUpdating = True
End Sub