Excel vba使工作表中的图形对象另存为图片

2019-11-02 17:09:00
tmtony8
原创
76

在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对象另存为图片。选择对象,可以看到两者的区别

    分享