I need to export a range to a PNG file.
Currently what I do is to
1. copy-paste that range into a picture object
2. copy-paste that picture to a chart to export
The problem is that the 2nd step does not preserve the quality (the clearness) of the picture, even when they are the same size. The exported png is much more blurred than manually copying that picture object to MS Paint then saving, where the quality is preserved (the texts in that png are sharp just like seen in Excel cells).
Is there a way to avoid using Chart as a step? Or, is there a way to export a picture while keeping its quality?
Below is the code that I currently have (revised from codes found on the internet), which outputs blurred text images.
I have Excel 2010 64 on Win7 64.
Thank you.
Currently what I do is to
1. copy-paste that range into a picture object
2. copy-paste that picture to a chart to export
The problem is that the 2nd step does not preserve the quality (the clearness) of the picture, even when they are the same size. The exported png is much more blurred than manually copying that picture object to MS Paint then saving, where the quality is preserved (the texts in that png are sharp just like seen in Excel cells).
Is there a way to avoid using Chart as a step? Or, is there a way to export a picture while keeping its quality?
Below is the code that I currently have (revised from codes found on the internet), which outputs blurred text images.
I have Excel 2010 64 on Win7 64.
Code:
Sub RangetoPNG(thatRange as Range)
Dim MyChart As String, MyPicture As String
Dim PicTop As Long, PicLeft As Long, PicWidth As Long, PicHeight As Long
'----- Step 1 --------
thatRange.Copy
Range("A1").Select
With ActiveSheet.Pictures.Paste
.Select
.Copy
End With
MyPicture = Selection.Name
With Selection
PicTop = .ShapeRange.Top
PicLeft = .ShapeRange.Left
PicHeight = .ShapeRange.Height
PicWidth = .ShapeRange.Width
End With
Selection.Delete
'----- Step 2 --------
With ActiveSheet.ChartObjects.Add(Left:=PicLeft, Top:=PicTop, Width:=PicWidth, Height:=PicHeight)
.Name = "ChartName1"
.Activate
End With
ActiveChart.Paste
ActiveSheet.ChartObjects("ChartName1").Chart.Export "c:\output.png"
ActiveSheet.ChartObjects("ChartName1").Delete
End Sub
Thank you.
Last edited: