Convert X - y coordiantes into a range - VBA

skimo

Board Regular
Joined
May 16, 2005
Messages
60
Hello

I am using this code to export an image "capture" of an excel range. However, I don't know the range of what I need to export, but i know the x - y cordiantes of the corners the area.

Code:
Private Sub SaveRngAsJPG(Rng As Range, FileName As String)
    Dim Cht As Chart, bScreen As Boolean, Shp As Shape
    bScreen = Application.ScreenUpdating
    Application.ScreenUpdating = False
    Set Cht = Workbooks.Add(xlChart).Charts(1)
    Cht.ChartArea.Clear
    Rng.CopyPicture xlScreen, xlPicture
    Cht.Paste
    With Cht.Shapes(1)
        .Left = 0
        .Top = 0
        .Width = Cht.ChartArea.Width
        .Height = Cht.ChartArea.Height
    End With
    Cht.Export FileName, "JPEG", False
    Cht.Parent.Close False
    Application.ScreenUpdating = bScreen
End Sub

Can the CopyPicture method accept X-Y coords? If not, how can I convert x-y into a range?

Thanks in advance!
skimo
 
OR:

Thinking more about this, I was able to play with the image size AFTER it was pasted into the chart. However, the problem is this chart is opened as a Worksheet (like when the whole tab is a chart). In this mode, the ratio of height to width of the chart is constant.

How can I modify this line:
Code:
 Set Cht = Workbooks.Add(xlChart).Charts(1)

to open a chart inside a sheet instead of make a whole sheet a chart? (tongue twister :-P )

thanks
 
Upvote 0

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