Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Export And Save Chart As PNG With Custom Sequential Name

  1. #1
    Junior Member
    Join Date
    Feb 2014
    Posts
    24
    Rep Power
    0

    Export And Save Chart As PNG With Custom Sequential Name

    I want to have png file name as d140302.png the next one d140303.png instead of Chart 49 02-03-14_03.42.51_PM.PNG please help me i attached the png fileAttachment 1501


    Code:
    Sub blah()
            With ThisWorkbook.Worksheets("min max & march of khamir")
              For i = 1 To 61 Step 2
                lr = .Cells(Rows.Count, i + 1).End(xlUp).Row
                .ChartObjects("Chart 2").Chart.SetSourceData Source:=.Range(.Cells(1, i), .Cells(lr, i + 1))
                .ChartObjects("Chart 2").Chart.Export ThisWorkbook.Path & Application.PathSeparator & "Chart " & Format(i, "00") & " " & Format(Now, "DD-MM-YY_HH.MM.SS_AM/PM") & ".PNG"
              Next i
            End With
            End Sub
    Last edited by Excel Fox; 03-03-2014 at 09:56 PM. Reason: Code Tag Added

  2. #2
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,402
    Rep Power
    10
    Use this
    Code:
    Format(now(),"""d""yymmdd"".PNG""")
    A dream is not something you see when you are asleep, but something you strive for when you are awake.

    It's usually a bad idea to say that something can't be done.

    The difference between dream and aim, is that one requires soundless sleep to see and the other requires sleepless efforts to achieve

    Join us at Facebook

  3. #3
    Member p45cal's Avatar
    Join Date
    Oct 2013
    Posts
    94
    Rep Power
    12
    This is really a continuation of this thread: http://www.excelfox.com/forum/f2/ins...bulletin-1712/
    where the dates to be used are on the sheet.
    Change the export line to:
    Code:
        .ChartObjects("Chart 2").Chart.Export ThisWorkbook.Path & Application.PathSeparator & "d" & Format(.Cells(1, i + 1).Value, "yymmdd") & ".PNG"

  4. #4
    Junior Member
    Join Date
    Feb 2014
    Posts
    24
    Rep Power
    0

    an error runtime error

    when i run this code in to this worksheet i face with this error .ChartObjects("Chart 2").Chart.SetSourceData Source:=.Range(.Cells(1, i), .Cells(lr, i + 1)) highlighted

    Code:
    Sub blah()
    With ThisWorkbook.Worksheets("min max & march of khamir")
      For i = 1 To 61 Step 2
        lr = .Cells(Rows.Count, i + 1).End(xlUp).Row
        .ChartObjects("Chart 2").Chart.SetSourceData Source:=.Range(.Cells(1, i), .Cells(lr, i + 1))
        .ChartObjects("Chart 2").Chart.Export ThisWorkbook.Path & Application.PathSeparator & "d" & Format(.Cells(1, i + 1).Value, "yymmdd") & ".PNG"
    
     Next i
    End With
    End Sub
    Last edited by Admin; 03-04-2014 at 08:28 AM. Reason: code tag added

  5. #5
    Administrator Admin's Avatar
    Join Date
    Mar 2011
    Posts
    1,123
    Rep Power
    10
    @ MARJAN_MASHAYEKHPOOR

    Please do not start a new thread. Stick with your original thread. Also please add code tags while posting codes.
    Cheers !

    Excel Range to BBCode Table
    Use Social Networking Tools If You Like the Answers !

    Message to Cross Posters

    @ Home - Office 2010/2013/2016 on Win 10 (64 bit); @ Work - Office 2016 on Win 10 (64 bit)

  6. #6
    Administrator Admin's Avatar
    Join Date
    Mar 2011
    Posts
    1,123
    Rep Power
    10
    Couple of things.

    1. Your chart name is "Chart 9"
    2. Your chart is in sheet "Sheet3"

    try this

    Code:
    Sub blah()
        
        Dim chtChart    As Chart
        Dim i           As Long
        Dim lRow        As Long
        
        Set chtChart = ThisWorkbook.Worksheets("Sheet3").ChartObjects("Chart 9").Chart
        
        With ThisWorkbook.Worksheets("min max & march of khamir")
            For i = 1 To 61 Step 2
                lRow = .Cells(Rows.Count, i + 1).End(xlUp).Row
                chtChart.SetSourceData Source:=.Range(.Cells(1, i), .Cells(lRow, i + 1))
                chtChart.Export ThisWorkbook.Path & Application.PathSeparator & "d" & Format(.Cells(1, i + 1).Value, "yymmdd") & ".PNG"
            Next i
        End With
        
    End Sub
    Cheers !

    Excel Range to BBCode Table
    Use Social Networking Tools If You Like the Answers !

    Message to Cross Posters

    @ Home - Office 2010/2013/2016 on Win 10 (64 bit); @ Work - Office 2016 on Win 10 (64 bit)

  7. #7
    Junior Member
    Join Date
    Feb 2014
    Posts
    24
    Rep Power
    0
    i think it is the last question about this thread...
    the title of column changed to text format cell as i send but i have to save my png as before so what should i do with this code and this excel file to have png export file as before (d140301.png)

    (i attached an image)

    Code:
    Sub blah()
        
        Dim chtChart    As Chart
        Dim i           As Long
        Dim lRow        As Long
        
        Set chtChart = ThisWorkbook.Worksheets("Sheet3").ChartObjects("Chart 9").Chart
        
        With ThisWorkbook.Worksheets("min max & march of khamir")
            For i = 1 To 61 Step 2
                lRow = .Cells(Rows.Count, i + 1).End(xlUp).Row
                chtChart.SetSourceData Source:=.Range(.Cells(1, i), .Cells(lRow, i + 1))
                chtChart.Export ThisWorkbook.Path & Application.PathSeparator & "d" & Format(.Cells(1, i + 1).Value, "yymmdd") & ".PNG"
            Next i
        End With
    Last edited by Excel Fox; 03-04-2014 at 07:31 PM. Reason: Code tags added

  8. #8
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,402
    Rep Power
    10
    Coral, you aren't adding code tags to your codes. Code tags add readability. Instruction is clearly given above the editor. Please ensure you follow this. Also, your last question is not clear. Can you please clarify.
    A dream is not something you see when you are asleep, but something you strive for when you are awake.

    It's usually a bad idea to say that something can't be done.

    The difference between dream and aim, is that one requires soundless sleep to see and the other requires sleepless efforts to achieve

    Join us at Facebook

  9. #9
    Junior Member
    Join Date
    Feb 2014
    Posts
    24
    Rep Power
    0
    Attachment 1503every thing is ok until i must change the title of column 01-mar-14 (format cell= date) in to 01-mar-2014 khamir (text format) so the export png file name is not as before and change from d140301.png in to d01-mar-2014 khamir.png
    so what should i do and how edit this line of code to have file names as d140301.png [PHP][Application.PathSeparator & "d" & Format(.Cells(1, i + 1).Value, "yymmdd") & ".PNG"
    Next i
    End With/PHP] the excel example is attached as image

  10. #10
    Junior Member
    Join Date
    Feb 2014
    Posts
    24
    Rep Power
    0
    Attachment 1506every thing is ok until i must change the title of column 01-mar-14 (format cell= date) in to 01-mar-2014 khamir (text format) so the export png file name is not as before and change from d140301.png in to d01-mar-2014 khamir.png
    so what should i do and how edit this line of code to have file names as d140301.png
    Code:
    Application.PathSeparator & "d" & Format(.Cells(1, i + 1).Value, "yymmdd") & ".PNG"
        Next i
        End With
    the excel example is attached as image

Similar Threads

  1. Custom Charts in Excel :: Gauge Chart (aka Dial/Speedometer Chart)
    By Transformer in forum Tips, Tricks & Downloads (No Questions)
    Replies: 0
    Last Post: 08-07-2013, 05:16 PM
  2. Custom Charts in Excel :: Butterfly Chart
    By Transformer in forum Tips, Tricks & Downloads (No Questions)
    Replies: 0
    Last Post: 07-04-2013, 12:42 PM
  3. Custom Charts in Excel :: Waterfall Chart
    By Transformer in forum Tips, Tricks & Downloads (No Questions)
    Replies: 0
    Last Post: 06-21-2013, 04:52 PM
  4. Replies: 1
    Last Post: 05-20-2012, 12:23 PM
  5. Save Chart As A Picture VBA
    By Admin in forum Excel and VBA Tips and Tricks
    Replies: 0
    Last Post: 05-14-2011, 04:28 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •