Sub SaveCharts()
Dim ws As Worksheet, chrtOb As Object, title, c As Long, p As Long, l As Long, ch As String
Const notvalid = "<>:""/\|?*"
l = Len(notvalid)
For Each ws In ThisWorkbook.Worksheets
For Each chrtOb In ws.ChartObjects
title = vbNullString
On Error Resume Next
title = chrtOb.Chart.ChartTitle.Caption
On Error GoTo 0
If title = vbNullString Then
title = chrtOb.Name
Else
For c = 1 To l
ch = Mid$(notvalid, c, 1)
p = 1
Do
p = InStr(p, title, ch)
If p <= 0 Then Exit Do
Mid$(title, p, 1) = "_"
Loop
Next
End If
chrtOb.Chart.Export filename:=ThisWorkbook.Path & "\" & title & ".PNG", Filtername:="PNG"
Next
Next
MsgBox "Charts Saved As Image File (png) in " & ThisWorkbook.Path
End Sub
这是一个简单的版本,没有检查...并使用图表的名称作为文件名。
Sub SaveCharts()
Dim ws As Worksheet, chrtOb As Object
For Each ws In ThisWorkbook.Worksheets
For Each chrtOb In ws.ChartObjects
chrtOb.Chart.Export filename:=ThisWorkbook.Path & "\" & chrtOb.Name & ".PNG", Filtername:="PNG"
Next
Next
MsgBox "Charts Saved As Image File (png) in " & ThisWorkbook.Path
End Sub
1条答案
按热度按时间yr9zkbsy1#
这是你问的,测试图形标题中用于文件名的无效字符。
这是一个简单的版本,没有检查...并使用图表的名称作为文件名。