|
Sub test()
Dim shp As Shape
Dim m As Integer
m = 10
For Each shp In Sheets(1).Shapes
With shp
.Top = .Top + m: .Left = .Left + m '调整
Call Chart2Pic(shp, .TopLeftCell.Offset(1, 0))
.Top = .Top - m: .Left = .Left - m '恢复
End With
Next
End Sub
'导出(对象, 文件名)
Sub Chart2Pic(shp As Shape, f As String)
shp.CopyPicture Appearance:=xlScreen, Format:=xlBitmap '将所选对象作为图片复制到剪贴板
With ActiveSheet.ChartObjects.Add(0, 0, shp.Width, shp.Height).Chart '创建嵌入式图表
.Paste '将剪贴板中的图表数据粘贴到指定的图表中
.Export Filename:=ThisWorkbook.Path & "\" & f & ".jpg" '以图形格式导出图表
.Parent.Delete
End With
End Sub
说明:
每个图片无论是否准确放入单元格(可能有的图片微微往左或往上,超出原来指定的单元格,肉眼很难发现)
1)调整。即 往右往下 移动10磅,这就几乎可保证 .TopLeftCell 正确
2)保存图片文件
3)恢复。
|
|