Excel vba使工作錶中的圖形對象另存爲圖片

2019-11-02 17:09:00
tmtony8
原創
77

在Excel中,我們可以在插入-形狀 插入圖形


下麵代碼可以對插入的shape形狀複製粘貼成gif格式的圖片

Sub SavePic()

    Dim shp As Shape, i As Integer
     With ActiveSheet
        For i = 1 To .Shapes.Count
            Set shp = .Shapes(i)
            shp.Copy
            With .ChartObjects.Add(0, 0, shp.Width, shp.Height + 5).Chart
                .Paste
                .Export ThisWorkbook.Path & "" & i & ".gif"
                '.Parent.Delete
            End With
        Next
    End With

End Sub



複製粘貼成功後,shape對象另存爲圖片。選擇對象,可以看到兩者的區彆

    分享