将图表导出为图像:在一个工作簿的各个工作表中都存在多个图表

时间:2018-07-16 14:41:56

标签: excel charts export high-resolution

在一本工作簿的各个工作表中都存在多个图表

导出的图像的名称必须是:作为图像标题的名称。PNG(高分辨率)

这是我的代码:

Sub export()

    Dim WS As Excel.Worksheet
    Dim SaveToDirectory As String
    Dim objChrt As ChartObject
    Dim myChart As Chart

    SaveToDirectory = ActiveWorkbook.Path & "\"

    For Each WS In ActiveWorkbook.Worksheets

         WS.Activate

        worksheetName = WS.Name
        If worksheetName = "EUROPE + ENG" Or worksheetName = "EUROPE" Or worksheetName = "NEW NORTH"Then

            For Each objChrt In WS.ChartObjects

                objChrt.Activate
                Set myChart = objChrt.Chart

                myFileName = SaveToDirectory & WS.Name & "_" & objChrt.Name & ".png"

                On Error Resume Next
                Kill SaveToDirectory & WS.Name & Name & ".png"
                On Error GoTo 0
                ActiveWindow.Zoom = 275
                myChart.export Filename:=myFileName, Filtername:="PNG"
                ActiveWindow.Zoom = 100

            Next            
        End If    
    Next

    MsgBox "Success !! All charts have been exported"
End Sub

0 个答案:

没有答案