+ Reply to Thread
Results 1 to 7 of 7

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

  1. #1
    Forum Contributor
    Join Date
    08-22-2017
    Location
    USA
    MS-Off Ver
    2016 WINDOWS and MAC
    Posts
    294

    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
    Forum Contributor
    Join Date
    12-02-2010
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2013, 2016
    Posts
    100

    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: Office 365 in Windows environment
    Posts
    8,613

    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: Office 365 in Windows environment
    Posts
    8,613

    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
    Forum Contributor
    Join Date
    08-22-2017
    Location
    USA
    MS-Off Ver
    2016 WINDOWS and MAC
    Posts
    294

    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
    Forum Contributor
    Join Date
    08-22-2017
    Location
    USA
    MS-Off Ver
    2016 WINDOWS and MAC
    Posts
    294

    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: Office 365 in Windows environment
    Posts
    8,613

    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)

Similar Threads

  1. Export excel range as image/screenshot in PowerPoint
    By karthikthandapani in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-09-2017, 06:21 AM
  2. How to export Cell range as Image without boarder line
    By dedark05 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-13-2016, 05:07 AM
  3. Macro to set Image as Desktop Background
    By ZEvans12 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-13-2016, 07:01 AM
  4. Replies: 4
    Last Post: 12-19-2014, 06:50 PM
  5. [SOLVED] Code to copy numerous sheet cell ranges to a word document on my desktop
    By matrixpom in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-21-2013, 07:48 PM
  6. VBA Export worksheet to CSV and save on desktop
    By jph89 in forum Excel General
    Replies: 0
    Last Post: 08-30-2012, 11:55 AM
  7. Excel export to Power Point--Image Scale code
    By VBNewb in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-16-2011, 08:21 AM

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