Excel visual basic (vba) resize and export all charts to png file

Excel visual basic (vba) resize and export all charts to png file

Sub LineUpMyCharts()

    Dim MyWidth As Single, MyHeight As Single
    Dim NumWide As Long
    Dim iChtIx As Long, iChtCt As Long

    MyWidth = 375
    MyHeight = 250
    NumWide = 2

    iChtCt = ActiveSheet.ChartObjects.Count

    For iChtIx = 1 To iChtCt
        With ActiveSheet.ChartObjects(iChtIx)
            .Width = MyWidth
            .Height = MyHeight
            .Left = ((iChtIx – 1) Mod NumWide) * MyWidth
            .Top = Int((iChtIx – 1) / NumWide) * MyHeight
        End With

        pngName = ActiveWorkbook.Path & “png” & iChtIx & “.png”
        ActiveSheet.ChartObjects(iChtIx).Activate
        ActiveChart.Export FileName:=pngName, FilterName:=”PNG”

    Next
End Sub

Tags: , , ,

No comments yet.

Leave a Reply