请教高手如何实现下面的功能??
1.当打开excel时,在工作表“sheet1”中添加图形msoShapeRectangle;
2.当点击工作表“sheet1”中的按钮则删除掉该矩形??
第一步通过录制宏 我知道在ThisWorkBook的
Private Sub Workbook_Open()
    Sheets("sheet1").Shapes.AddShape(msoShapeRectangle, 100, 100, 200#, 6#). _
        Select    Selection.ShapeRange.ThreeD.Visible = msoFalse
  
    Selection.ShapeRange.Fill.Transparency = 0#
    Selection.ShapeRange.Line.Weight = 0.75
    Selection.ShapeRange.Line.DashStyle = msoLineSolid
    Selection.ShapeRange.Line.Style = msoLineSingle
End Sub但是第二步不知道如何实现了,请高手指点,谢谢~

解决方案 »

  1.   

    dim a as shape
    for each a in sheets("sheet1").shapes
    if a.name=........或a.type=.... then
    a.delete
    end if
    next
      

  2.   

    Option Explicit
    'Thisworkbook
    Private Sub Workbook_Open()
        Sheets("sheet1").Shapes.AddShape(msoShapeRectangle, 100, 100, 200#, 6#). _
            Select    Selection.ShapeRange.ThreeD.Visible = msoFalse
        Sheet1.CommandButton1.Caption = Selection.Name '保留图形名称
        Selection.ShapeRange.Fill.Transparency = 0#
        Selection.ShapeRange.Line.Weight = 0.75
        Selection.ShapeRange.Line.DashStyle = msoLineSolid
        Selection.ShapeRange.Line.Style = msoLineSingle
    End Sub'下面在Sheet1中
    Private Sub CommandButton1_Click()
        On Error Resume Next
        Sheet1.Shapes(CommandButton1.Caption).Delete
    End Sub