I'm using the code below to export and save a range (yes, it's a large range!) to an image file. Is there a way to get a higher resolution image using this method?Or is it a limitation of how CopyPicture works with a chart? Or an issue with the size of my range? Gif was no better, and trying a bitmap ended up with a ~200mb image file! The JPG images are only about 40k each. I also tried changing the size of the chart object, but that seems to just stretch the image.
Also, while we're here, I occasionally get an error raised on the line that I highlighted below, which is why I have the error handler looping back to try it again. It will run fine after a couple repeated passes. Any ideas on how to fix that? I tried adding a wait time of up to 5 seconds just before that line, but that didn't seem to help
Also, while we're here, I occasionally get an error raised on the line that I highlighted below, which is why I have the error handler looping back to try it again. It will run fine after a couple repeated passes. Any ideas on how to fix that? I tried adding a wait time of up to 5 seconds just before that line, but that didn't seem to help
Code:
Sub Export_Range_Image()
' =========================================
' Code to save selected Excel Range as Image
' =========================================
Dim oRange As Range
Dim oCht As Chart
Dim oImg As Picture
Dim nowTime As String
Dim tryagainloop As Integer
Dim ShTemp As Worksheet
Application.ScreenUpdating = False
Set oRange = ActiveSheet.Range("A1:TD256")
Set ShTemp = Worksheets.Add
Charts.Add
ActiveChart.location Where:=xlLocationAsObject, Name:=ShTemp.Name
Set oCht = ActiveChart
On Error GoTo TryAgain
TryAgain:
Err.Clear
[COLOR="Yellow"]oRange.CopyPicture xlScreen, xlPicture[/COLOR]
oCht.Paste
On Error Resume Next
MkDir ThisWorkbook.Path & "\Saved_Images"
oCht.Export Filename:=ThisWorkbook.Path & "\Saved_Images\" & nowDate & " - " & VisTitle & ".jpg", Filtername:="JPG"
Application.DisplayAlerts = False
ShTemp.Delete
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub