+ Reply to Thread
Results 1 to 9 of 9

Save charts as image and incrementing file name

  1. #1
    Registered User
    Join Date
    04-19-2012
    Location
    UK
    MS-Off Ver
    Excel 365
    Posts
    41

    Save charts as image and incrementing file name

    Hi all, I know this is a relatively simple one, but just cant think clearly enough today
    Basically I am making a macro function to save a copy of a chart as an image file to a specific folder. The chart is a pivot chart and so I am changing the values and saving again after running the macro again, but want the image to be saved with a new file name ie not overwriting the existing one, so ending up with a folder with chartimg1.jpg, chartimg2.jpg, etc..

    Below is the code I have after playing around, I know I'm close as i did have it working. It saved the chart jpeg fine, but it just got overwritten when I ran it again to create the net jpeg.

    Please Login or Register  to view this content.

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482

    Re: Save charts as image and incrementing file name

    try counting the files in the folder first.

    Please Login or Register  to view this content.
    It assumes the files already in the folder are sequentially numbers and numbering starts at 1.
    Also that when run the file names will always be unique.

    If the numbering is erratic you can decode the ExportName and extract the number and remember the largest value and begin incrementing from that number.
    Cheers
    Andy
    www.andypope.info

  3. #3
    Registered User
    Join Date
    04-19-2012
    Location
    UK
    MS-Off Ver
    Excel 365
    Posts
    41

    Re: Save charts as image and incrementing file name

    Thanks for your reply, I knew it had to be some sort of loop with imcrementing. Have done similar in Java but forgotten it all

    Just trying this now but getting a runtime error '13' - type mismatch, on the line 'Set sheetObj = ActiveSheet'. Any ideas?

  4. #4
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482

    Re: Save charts as image and incrementing file name

    If the activesheet a worksheet? if not then the code will fail.

  5. #5
    Registered User
    Join Date
    04-19-2012
    Location
    UK
    MS-Off Ver
    Excel 365
    Posts
    41

    Re: Save charts as image and incrementing file name

    The active sheet is a tab that contains a pivot chart, but would that not be classed as a worksheet?

  6. #6
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482

    Re: Save charts as image and incrementing file name

    If the pivot chart is the only thing on the sheet, that is there are no cells, then it's a chart sheet.

    You could check the icon used in the VBA project view. ALT+F11, CTRL+R
    Inside the Microsoft Excel Objects folders you should see sheets, charts and Thisworkbook. worksheets have a grid icon and charts have a chart icon

  7. #7
    Registered User
    Join Date
    04-19-2012
    Location
    UK
    MS-Off Ver
    Excel 365
    Posts
    41

    Re: Save charts as image and incrementing file name

    Ah I see, it does appear to be a chart sheet. Is there a workaround or can this method not be used?

  8. #8
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482

    Re: Save charts as image and incrementing file name

    Please Login or Register  to view this content.
    If the active sheet is a chart then you can use the above.
    No need to loop as it's a single chart.

  9. #9
    Registered User
    Join Date
    04-19-2012
    Location
    UK
    MS-Off Ver
    Excel 365
    Posts
    41

    Re: Save charts as image and incrementing file name

    Thank you, works perfectly!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 32
    Last Post: 07-17-2018, 03:08 AM
  2. Save charts in a Excel file into another new one
    By hong in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-05-2005, 08:05 AM
  3. [SOLVED] Convert, export, or save Word as an image file (jpg, gif, png, etc
    By rjamison in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-13-2005, 08:05 PM
  4. Re: Convert, export, or save Word as an image file (jpg, gif, png, etc
    By rjamison in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-13-2005, 08:05 PM
  5. [SOLVED] Convert, export, or save Word as an image file (jpg, gif, png, etc
    By quartz in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-20-2005, 12:06 PM

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