+ Reply to Thread
Results 1 to 7 of 7

vba - Export cell range to image on desktop! Help with code

  1. #1
    Registered User
    Join Date
    08-22-2017
    Location
    USA
    MS-Off Ver
    2016 WINDOWS and MAC
    Posts
    38

    vba - Export cell range to image on desktop! Help with code

    Hi all,

    What I am trying to do is relatively simple but requires a fair bit of code from what I understand... I am trying to simply have a macro that exports a constant cell range (i.e. A1:C10) to an image file on the desktop. PNG is fine. But the image must be of decent quality. Which all the solutions for this problem result in the chart method, where the code creates a chart from cells and then exports that chart. The quality is sacraficed. The other method is using the print page function.

    I found the best code I could, I like all the added features, such as msg box, desktop file path of CURRENT user, and a file name prompt. But it requires you to manually select the cells. Not to mention, it does not work!

    Can someone write similar code for me that achieves this?

    HERE IS SOURCE: https://stackoverflow.com/questions/...-in-excel-2003

    Code:
    Please Login or Register  to view this content.
    Thank you

  2. #2
    Registered User
    Join Date
    12-02-2010
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2013, 2016
    Posts
    99

    Re: vba - Export cell range to image on desktop! Help with code

    ironfelix717,

    I too have had quality issues when exporting images using the chart method. The solution that has worked for me in the past is to modify the scale value on the chart. I would either change the currently existing line of code:
    Please Login or Register  to view this content.
    to something larger, or after you paste the image you can scale it some:
    Please Login or Register  to view this content.
    The way I am reading the code the simple zoom coefficient method I listed first might work, but if not try the second bit of code. In the second bit of code the values in red are from one of my other spreadsheets, so those numbers will most likely need to be modified to your particular use. Either way, please let me know if this helped resolve your issue.

    Thanks,

    DarkF1ame
    Mark as "Solved" and add Reputation if applicable.

  3. #3
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: 2010, 2016
    Posts
    5,376

    Re: vba - Export cell range to image on desktop! Help with code

    I believe issue here is that you want to use this code in Excel 2016.

    The chart object shall be activated before pasting.
    Try:
    Please Login or Register  to view this content.
    Best Regards,

    Kaper

  4. #4
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: 2010, 2016
    Posts
    5,376

    Re: vba - Export cell range to image on desktop! Help with code

    PS, and of course range to be printed is defined here:
    Please Login or Register  to view this content.
    So why not white instead:
    Please Login or Register  to view this content.
    Probably this code could be further simplified, but if it works ...

  5. #5
    Registered User
    Join Date
    08-22-2017
    Location
    USA
    MS-Off Ver
    2016 WINDOWS and MAC
    Posts
    38

    Re: vba - Export cell range to image on desktop! Help with code

    Hi all, thanks for the replies. Much Appreciated.

    I decided to first try Kaper's method. It seems I was only missing the activate.chart call. I then used Kaper's suggestion to remove the selection objects and replace with a range.

    The resulting code is as follows:

    Please Login or Register  to view this content.

    Thank you very much!!!

  6. #6
    Registered User
    Join Date
    08-22-2017
    Location
    USA
    MS-Off Ver
    2016 WINDOWS and MAC
    Posts
    38

    Re: vba - Export cell range to image on desktop! Help with code

    Hi all,
    back again with another question...

    Is there anyway I can have an OVERWRITE warning with this code? I will have multiple macros with this code, which the user can export an image for different parts of the spreadsheet. However, assume the user is lazy (which is how we all are, lets admit it), and chooses to not change the file name, the exported file is overwritten without warning. Any way to implement this or is this diving to much into windows to be possible?

    Thanks

  7. #7
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: 2010, 2016
    Posts
    5,376

    Re: vba - Export cell range to image on desktop! Help with code

    Try:
    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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