分享

Excel VBA

 松飞书馆 2018-12-19
'r,c 图片所在单元格的偏移量,用来做图片的名字 
Sub exportPic() 
r = 0 
c = -2 
    For i = 1 To ActiveSheet.Shapes.Count 
        ActiveSheet.Shapes(i).Select 
        Name = Range(ActiveSheet.Shapes(i).TopLeftCell.Address).Offset(r, c) 
        H = Selection.Height 
        W = Selection.Width 
        Selection.ShapeRange.ScaleHeight 1#, msoFalse, msoScaleFromTopLeft 
        Selection.ShapeRange.ScaleWidth 1#, msoFalse, msoScaleFromTopLeft 
        Selection.CopyPicture 
 
        Set myChart = ActiveSheet.ChartObjects.Add(0, 0, Selection.Width - 2, Selection.Height - 2).Chart 
        myChart.Paste 
        ActiveSheet.Shapes(ActiveSheet.Shapes.Count).Line.Visible = msoFalse '去掉Chart边框 
        ActiveSheet.Shapes(ActiveSheet.Shapes.Count).Fill.Visible = msoFalse '去掉Chart填充 
        myChart.Export ThisWorkbook.Path & "\" & Name & ".png" 
        myChart.Parent.Delete
 
        ActiveSheet.Shapes(i).Select 
        Selection.Height = H 
        Selection.Width = W 
   Next 
End Sub  

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约