Range to Image

lawvictor

New Member
Joined
Jul 29, 2017
Messages
27
Hi All,
I ma writing a script to covert a given range into image, i found a code from which was working fine as long as the range was smaller width but the moment i increased the width of the column it is not working, the whole image is not creating. the below is the steps how the code works,
1) selects the range, find it height and width,
2) inserts a chart and changes the height and width to the range height and width,
3) paste the copied range into the chart
4) export the chart as image.

i find that the chart gets modified to the size of the range however the image pasted in it is no the full image,

any help would be useful.
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Please post your existing code - it may be easiest to modify it

Click on "Reply to Thread" and then on # icon (above post window) and..
Code:
[COLOR=#ff0000][I] paste your code here [/I][/COLOR][ /CODE]
 
Last edited:
Upvote 0
below is the code, however i understand the issue is due to the area of the excel sheet visible on the screen, it is converting to the full image only if the selected range is visible on the screen, if it is not visible, it converts only that portion which is visible on the screen. I tried zoom out but still my range is out of the screen and it is not converting the whole range. If if do the same using the lower column value it gives me the image for the full selected range.

Code:
<code>dim sSheetName as string
dim oRangeToCopy as range
Dim oCht As Chart

sSheetName ="Sheet1" ' worksheet to work on
set  oRangeToCopy =Range("B2:H8") ' range to be copied

Worksheets(sSheetName).Range(oRangeToCopy).CopyPicture xlScreen, xlBitmap
set oCht =charts.add

with oCht
    .paste
    .Export FileName:="C:\SavedRange.jpg", Filtername:="JPG"
end with</code>
 
Upvote 0
You carried out a bad cut and paste job on your code and posted it untested :)
- the code fails

Please test your code before posting it again
- ensure that the code actually runs
- verify that the jpg is a picture of the actual range and not a random chart

thanks
 
Last edited:
Upvote 0
yongle, i cannot paste the actual code here, hence i had to paste one from which i was able to convert range to image,

what do you mean by:
- verify that the jpg is a picture of the actual range and not a random chart.

I am trying to create the picture of actual range here,
 
Upvote 0
<code><code>
i cannot paste the actual code here, hence i had to paste one from which i was able to convert range to image
I appreciate confidentiality issues and understand you providing edited code
BUT do not expect to be required correct code which fails to run as described before starting to help you with your problem

Run the code you actually posted and you will see that
1. it does not copy a picture of your range into the chart (hopefully it will after you correct it)
2. it fails to run because of this
Code:
set [COLOR=#ff0000]oRangeToCopy[/COLOR] =Range("B2:H8") is a [COLOR=#ff0000]range[/COLOR] 
BUT 
Range([COLOR=#ff0000]oRangeToCopy[/COLOR]) is looking for a [COLOR=#ff0000]string[/COLOR]

Delete the image that is currently in your folder and check the image that the "posted" code creates





<code></code></code>










</code>
 
Last edited:
Upvote 0
thanks Yongle,
Yes am able to run the code that i pasted after correcting, it actaully works fine when the range is small, but when the range is of order Range("A1:CD11") with each column width size 60, it fails to copy paste the full range into the chart which is later converted to jpeg,
the code i have works fine with less range and with the lesser column width.

When is the range is big it gives only portion of the range as image and not the full range.
 
Upvote 0
No Jafer, it still doesnt works, even the code which you had in that thread generates the image which is visible in the screen and not the full range, my range could be even bigger that (A1:CD11) which am currently trying to create image.
It just generates the image upto A1:AS11.

Any thoughts on it.
 
Upvote 0

Forum statistics

Threads
1,223,901
Messages
6,175,277
Members
452,629
Latest member
SahilPolekar

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top