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.
 

Some videos you may like

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.

Yongle

Well-known Member
Joined
Mar 11, 2015
Messages
6,781
Office Version
  1. 365
Platform
  1. Windows
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:

lawvictor

New Member
Joined
Jul 29, 2017
Messages
27
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>
 

Yongle

Well-known Member
Joined
Mar 11, 2015
Messages
6,781
Office Version
  1. 365
Platform
  1. Windows
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:

lawvictor

New Member
Joined
Jul 29, 2017
Messages
27

ADVERTISEMENT

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,
 

Yongle

Well-known Member
Joined
Mar 11, 2015
Messages
6,781
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

<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:

lawvictor

New Member
Joined
Jul 29, 2017
Messages
27
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.
 

lawvictor

New Member
Joined
Jul 29, 2017
Messages
27
thanks Jaffar, let me try and work around that post, seems promising one. thanks
 

lawvictor

New Member
Joined
Jul 29, 2017
Messages
27
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,109,425
Messages
5,528,687
Members
409,830
Latest member
KT50

This Week's Hot Topics

  • Change military grades into rank
    Afternoon all Need help with formula that will change military rank (i.e. 1, 2, 3 into Amn, A1C, SrA). Running IF formula that does not work...
  • VBA COUNTIF SOLUTION
    Hi The following are the errors spread across the several columns from E to Q ie. 13 columns across several sheets with more than 500 rows per...
  • INSERT ROW WITH SPECIFIS TEXT IN A COLUMN
    Hi All! How can identify that that the row to be inserted has to be inserted before 1st row with specific text in column F. If I record the...
  • Auto-Create a monthly Sign in sheet for preschool students
    The image below is what each page looks like. Above is space for the "Child Name" "Month" "Class" School days are obviously Monday-Friday but...
  • VBA vlookup multiple results
    Hi folks, Hopefully someone out there can help. I have a list to vlookup which works (ish). the lookup only picks up the first instance of the...
  • Extract values for earliest/latest times
    I am trying to put together a formula to get the earliest start time, the latest end time from column A for each person in Column B-F without the...
Top