首页 > 编程知识 正文

Excel VBA-批量导出图片.vba

时间:2023-05-04 04:05:26 阅读:255251 作者:3471

'r,c 图片所在单元格的偏移量,用来做图片的名字Sub exportPic()r = 0c = -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 NextEnd Sub

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。