none
Excel 2010 VBA code to save multiple charts is misnaming them on one sheet RRS feed

  • Question

  • This is truly frustrating. I've deleted the sheet and re-created the charts, but the charts on that one sheet only, I have three sheets with charts, are misnamed. I've checked and re-checked the chart names and they are correct. It's almost as if there's an underlying list for the charts that is incorrect. If so, I can't find it. Here is the code I use to export my charts:

    Sub ChartsMonthlySave()
    '
        Dim ChtObj As ChartObject
        Dim Fname As String
    Sheets("3 Charts").Select
        For Each ChtObj In ActiveSheet.ChartObjects
            ChtObj.Activate(change)
    ChtObj.Chart.Export Filename:=Fname, FilterName:="png"
            Fname = "c:\users\rick\my documents\my web sites\Desert - New\charts" & "\" & ChtObj.Name & ".png"
      Next ChtObj
    Sheets("12 Charts").Select
        For Each ChtObj In ActiveSheet.ChartObjects
            ChtObj.Activate
    Fname = "c:\users\rick\my documents\my web sites\Desert - New\charts" & "\" & ChtObj.Name & ".png"
            ChtObj.Chart.Export Filename:=Fname, FilterName:="png"
      Next ChtObj
    Sheets("Misc").Select
        For Each ChtObj In ActiveSheet.ChartObjects
            ChtObj.Activate
    Fname = "c:\users\rick\my documents\my web sites\Desert - New\charts" & "\" & ChtObj.Name & ".png"
            ChtObj.Chart.Export Filename:=Fname, FilterName:="png"
      Next ChtObj
    End Sub

    • Moved by Youen Zen Monday, March 5, 2012 5:44 AM To provide a better support (From:Visual Basic General)
    Friday, March 2, 2012 9:24 PM

All replies

  • This forum is about the .Net based standalone versions of Visual Basic. Please have a look at this forum instead:
    http://social.msdn.microsoft.com/Forums/en-US/exceldev/threads


    Armin

    Friday, March 2, 2012 9:42 PM
  • Hi Rdcsfd,

    Welcome to the MSDN forum.

    This is a VBA issue. In order to give you a better support, I will move it from “Visual Basic General” forum to “Visual Basic for Applications (VBA)” forum.

    Have a nice day!

    Best regards,


    Shanks Zen
    MSDN Community Support | Feedback to us

    Monday, March 5, 2012 5:44 AM
  • 1.In the 3 Charts the Fname should be assigned before exporting.As Fname is empty you will never get the PNG for one chart of 3 Charts sheet.

    For Each ChtObj In ActiveSheet.ChartObjects
            ChtObj.Activate

    ChtObj.Chart.Export Filename:=Fname, FilterName:="png"
            Fname = "c:\users\rick\my documents\my web sites\Desert - New\charts" & "\" & ChtObj.Name & ".png" 'This should be used before exporting
      Next ChtObj

    2.The code runs perfectly.I think the problem is due to name assignment.

    The chart name you are assigning manually should be assigned from Chart Tools->Lay Out Tab->Proprties Tab.

    If you assign by address bar it will not work.

    Monday, March 5, 2012 8:21 AM
    Answerer