【发布时间】:2022-07-01 22:50:21
【问题描述】:
我想将工作表中已有的形状转换为按钮。我已经搜索过了,但我只能找到如何从 excel 本身而不是通过 VBA 将宏添加到按钮。
有可能吗?
【问题讨论】:
我想将工作表中已有的形状转换为按钮。我已经搜索过了,但我只能找到如何从 excel 本身而不是通过 VBA 将宏添加到按钮。
有可能吗?
【问题讨论】:
可以使用 OnAction
Sub gen_button()
l = ActiveSheet.Range("H10:H11").Left
t = ActiveSheet.Range("H10:H11").Top
w = ActiveSheet.Range("H10:H11").Width
h = ActiveSheet.Range("H10:H11").Height
Set shp = ActiveSheet.Shapes.AddShape(msoShapeRectangle, l, t, w, h)
shp.OnAction = "Shape_Click"
shp.Select
Selection.ShapeRange.Line.Visible = msoFalse
Selection.Text = "Generaty"
Selection.Font.Color = RGB(0, 0, 0)
Selection.HorizontalAlignment = 1
Selection.ShapeRange.Fill.ForeColor.RGB = RGB(0, 255, 0)
End Sub
【讨论】: