【问题标题】:Can I convert a shape into a button within VBA?我可以在 VBA 中将形状转换为按钮吗?
【发布时间】:2022-07-01 22:50:21
【问题描述】:

我想将工作表中已有的形状转换为按钮。我已经搜索过了,但我只能找到如何从 excel 本身而不是通过 VBA 将宏添加到按钮。

有可能吗?

【问题讨论】:

    标签: excel vba


    【解决方案1】:

    可以使用 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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-09-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-06-30
      • 2011-12-30
      • 1970-01-01
      相关资源
      最近更新 更多