Closed Thread
Results 1 to 33 of 33

Export charts from an excel file as images and name the image files by the charts title

  1. #1
    Registered User
    Join Date
    09-30-2012
    Location
    Tel-Aviv
    MS-Off Ver
    Excel 2010
    Posts
    84

    Export charts from an excel file as images and name the image files by the charts title

    Hi all,
    I was wondering if someone knows how to do the following, or can refer to an implementation of such a thing.

    I have an excel file with many sheets and charts scattered in the various sheets.
    I'd like to export all charts to a folder as image files.
    I'd like the file names to be determined by the chart title.
    Alternatively, by the chart name.

    I managed to go as far as this:
    http://msdn.microsoft.com/en-us/libr.../ff198129.aspx
    Can anyone help?

    Thanks in advance
    Optimesh

    (p.s. I have both office 2010 and 2013)

  2. #2
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: Export charts from an excel file as images and name the image files by the charts titl

    Hi,
    you may look at this http://j-walk.com/ss/excel/usertips/tip065.htm

    buran
    If you are pleased with a member's answer then use the Star icon to rate it.

  3. #3
    Registered User
    Join Date
    09-30-2012
    Location
    Tel-Aviv
    MS-Off Ver
    Excel 2010
    Posts
    84

    Re: Export charts from an excel file as images and name the image files by the charts titl

    Hi Buran,
    Thanks for this,
    It's a start but it only exports one chart at a time... What I'm looking it is dozens of charts scattered across multiple sheets..

  4. #4
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: Export charts from an excel file as images and name the image files by the charts titl

    Hi,
    here is small macro that will do the job.

    Please Login or Register  to view this content.
    Note that it will not check if chart exists in the export folder and my overwrite it.

    Buran

  5. #5
    Registered User
    Join Date
    09-30-2012
    Location
    Tel-Aviv
    MS-Off Ver
    Excel 2010
    Posts
    84

    Re: Export charts from an excel file as images and name the image files by the charts titl

    Wow, this is amazing. Thank you so much!

  6. #6
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: Export charts from an excel file as images and name the image files by the charts titl

    Great! Don't forget to mark thread SOLVED :-)

  7. #7
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: Export charts from an excel file as images and name the image files by the charts titl

    I noticed small error in my code.
    Make following change in the code:

    Please Login or Register  to view this content.
    i.e. take lngChartSheetsCount = 0 out of the loop.

    stupid mistake

    Buran

  8. #8
    Registered User
    Join Date
    09-30-2012
    Location
    Tel-Aviv
    MS-Off Ver
    Excel 2010
    Posts
    84

    Re: Export charts from an excel file as images and name the image files by the charts titl

    Could you please provide the full corrected code? I got confused...

    BTW, is there a way to export to PNG or high res jpg? Somehow I lost image quality..

    Thanks again

  9. #9
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: Export charts from an excel file as images and name the image files by the charts titl

    Here is the correct code

    Please Login or Register  to view this content.
    The change does not affect the export, just the count of exported chart sheets, displayed in the msg box at the end.

  10. #10
    Registered User
    Join Date
    09-30-2012
    Location
    Tel-Aviv
    MS-Off Ver
    Excel 2010
    Posts
    84

    Re: Export charts from an excel file as images and name the image files by the charts titl

    Thank you for helping out again and so quickly.

    Is PNG an option?

    Thanks
    O.

  11. #11
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: Export charts from an excel file as images and name the image files by the charts titl

    I think you can export in different format, just make the appropriate changes - change the file extension in the file name and the filter name. It's different format as you can see that the file size is different. However, I'm not sure you can control the resolution, what you actually want...

  12. #12
    Registered User
    Join Date
    09-30-2012
    Location
    Tel-Aviv
    MS-Off Ver
    Excel 2010
    Posts
    84

    Re: Export charts from an excel file as images and name the image files by the charts titl

    it works with PNGs... but only for sum of the charts.. c'est la vie I guess...

    thanks a lot!

  13. #13
    Registered User
    Join Date
    09-30-2012
    Location
    Tel-Aviv
    MS-Off Ver
    Excel 2010
    Posts
    84

    Re: Export charts from an excel file as images and name the image files by the charts titl

    Hi,
    Me again.
    It's strange - the macro consistantly fails to export some of the charts as images while it does export the rest.
    Any idea why? How to make it export all of them?
    I can't believe it's a memory issue... my processor is i7 with 8 gigs of ram...

    Your help would once again be appreciated
    Thank you

  14. #14
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: Export charts from an excel file as images and name the image files by the charts titl

    Any consistent pattern - e.g. type of charts or anything else.
    If you change the order of the worksheets and run the macro again, does in it export charts that it doesn't before that?
    if you move just one of the charts that is not exported in a different new workbook, what is going on?
    without sample workbook I can't help much

  15. #15
    Registered User
    Join Date
    09-30-2012
    Location
    Tel-Aviv
    MS-Off Ver
    Excel 2010
    Posts
    84

    Re: Export charts from an excel file as images and name the image files by the charts titl

    Hi,
    thanks for the quick reply.
    Unfortunately I can't share the workbook (sensitive data).

    I had a hunch it may be related to the charts' titles (e.g. charts titles that start with "%") but couldn't validate it so far.

    As a first step, is it possible for you to modify the macro so it would only export charts from a specific sheet ? (and instruct me how to specify which sheet it exports)

    Thanks again

  16. #16
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: Export charts from an excel file as images and name the image files by the charts titl

    Here it is

    Please Login or Register  to view this content.
    Add worksheet names to the arrays at the beginning of the code

  17. #17
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: Export charts from an excel file as images and name the image files by the charts titl

    btw, I do tried to export chart that has a title starting with % and it worked fine.

  18. #18
    Registered User
    Join Date
    09-30-2012
    Location
    Tel-Aviv
    MS-Off Ver
    Excel 2010
    Posts
    84

    Re: Export charts from an excel file as images and name the image files by the charts titl

    Thanks for the code.

    The problem still persists. It appears that the same charts aren't exported everytime. To be precise, a gif file named with the chart's title is created, but it is blank.

    All of the charts in the sheet I tried now are very similar one to the other. Sames size, format, type... just the values themselves that are different.

    Strange.

  19. #19
    Registered User
    Join Date
    09-30-2012
    Location
    Tel-Aviv
    MS-Off Ver
    Excel 2010
    Posts
    84

    Re: Export charts from an excel file as images and name the image files by the charts titl

    Here's an interesting finding:
    I took one of the charts that wasn't exporting well.
    I placed it at the top of the worksheet.
    Now it exports well.

    Does that help with the debugging ?

  20. #20
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: Export charts from an excel file as images and name the image files by the charts titl

    Unfortunately not. that's very odd

  21. #21
    Registered User
    Join Date
    09-30-2012
    Location
    Tel-Aviv
    MS-Off Ver
    Excel 2010
    Posts
    84

    Re: Export charts from an excel file as images and name the image files by the charts titl



    Any ideas how to move forward ?

  22. #22
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: Export charts from an excel file as images and name the image files by the charts titl

    sorry for the delay. probably - remove [Solved] label and maybe other users could suggest something...

  23. #23
    Registered User
    Join Date
    09-30-2012
    Location
    Tel-Aviv
    MS-Off Ver
    Excel 2010
    Posts
    84

    Re: Export charts from an excel file as images and name the image files by the charts titl

    Thanks, I just did. Let's hope for the best. Please let me know if you have any ideas how to debug it or find a solution.

    Thanks a lot for your help. Sorry it took me a few days to reply - I was on holiday and away from keyboard...

  24. #24
    Registered User
    Join Date
    09-06-2013
    Location
    SLP
    MS-Off Ver
    Excel 2013
    Posts
    1

    Re: Export charts from an excel file as images and name the image files by the charts titl

    You sir buran are a master, thank you very much

  25. #25
    Registered User
    Join Date
    08-04-2013
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    1

    Re: Export charts from an excel file as images and name the image files by the charts titl

    That is immense - I've been trying to work that out for 2 days and it works a treat! Next up how to import the charts into Access! Thank you!

  26. #26
    Registered User
    Join Date
    05-17-2018
    Location
    slovenia
    MS-Off Ver
    2016
    Posts
    1

    Re: Export charts from an excel file as images and name the image files by the charts titl

    Wow.
    Thanx it works.
    Now only to update code When Saving/Exiting Excel Workbook then this macro should trigger. and its PERFECT.
    Thank you

  27. #27
    Registered User
    Join Date
    07-13-2018
    Location
    Germany
    MS-Off Ver
    10
    Posts
    5

    Re: Export charts from an excel file as images and name the image files by the charts titl

    Thank you very much

    Could you please paste the code which would export the images and save them as a chart title name IT is exporting as a GIF but not PNG

    I would be grateful if you would please modify my code :

    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" Or worksheetName = "SOUTH" Or worksheetName = "TALENT HUB A" Or worksheetName = "TALENT HUB B" Or worksheetName = "Compliant sites hdct" Or worksheetName = "Compliant sites cost" 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

  28. #28
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: Export charts from an excel file as images and name the image files by the charts titl

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Click on Edit to open your thread, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)

  29. #29
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    79,369

    Re: Export charts from an excel file as images and name the image files by the charts titl

    SumitShinde - Unfortunately your post does not comply with Rule 2 of our Forum RULES. Do not post a question in the thread of another member -- start your own thread.

    If you feel an existing thread is particularly relevant to your need, provide a link to the other thread in your new thread.

    Old threads are often only monitored by the original participants. New threads not only open you up to all possible participants again, they typically get faster response, too.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  30. #30
    Registered User
    Join Date
    07-13-2018
    Location
    Germany
    MS-Off Ver
    10
    Posts
    5

    Re: Export charts from an excel file as images and name the image files by the charts titl

    Hello Buran ...
    Thanks a lot for your help..

    Could you also add code to export the image as a high resolution?
    i.e. ActiveZoom?

    Thanks in advance....

  31. #31
    Registered User
    Join Date
    07-13-2018
    Location
    Germany
    MS-Off Ver
    10
    Posts
    5

    Re: Export charts from an excel file as images and name the image files by the charts titl

    Why it is exporting as GIF and not PNG?

  32. #32
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: Export charts from an excel file as images and name the image files by the charts titl

    You have been advised by AliGW to start new thread. Always follow Mod's requests. And follow forum rules.

  33. #33
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    79,369

    Re: Export charts from an excel file as images and name the image files by the charts titl

    I have closed this thread, as SumitShinde seems to be ignoring my request to start a new thread. This will prevent him/her from posting to this thread again.

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1