|
Sub test()
Dim p, f
Application.ScreenUpdating = False
p = ThisWorkbook.Path & "\"
If Dir(p & "Pic", vbDirectory) = "" Then MkDir p & "Pic"
f = Dir(p & "Data\")
Do While f <> ""
Call test2(p, f)
f = Dir
Loop
End Sub
'某个工作簿
Sub test2(p, f)
Dim wb, sh, c, str
Set wb = Workbooks.Open(p & "Data\" & f)
For Each sh In wb.Sheets
For Each c In sh.ChartObjects
str = Split(wb.Name, ".")(0) & "_" & sh.Name & "日_" & c.Index
str = VBA.Replace(str, "-", "月")
Call test3(c, p & "Pic\" & str & ".jpg")
Next c
Next sh
wb.Close False
End Sub
'某个图表(对象, 路径)
Sub test3(obj, f)
obj.CopyPicture Appearance:=xlScreen, Format:=xlBitmap '将所选对象作为图片复制到剪贴板
With ActiveSheet.ChartObjects.Add(0, 0, obj.Width, obj.Height).Chart '创建嵌入式图表
.Paste '将剪贴板中的图表数据粘贴到指定的图表中
.Export Filename:=f '以图形格式导出图表
.Parent.Delete
End With
End Sub
1.rar
(584.64 KB, 下载次数: 11)
|
|