I have a macro I have been using for years where a range of cells is copied using the CopyPicture method. The macro then creates a chart object, pastes the picture into the chart, then exports the chart as a jpg. Finally, the chart is deleted. This has worked with Excel 2010 just fine, but now gives me an empty jpg file with Excel 2016.
Here's the code that works:
With ActiveSheet
Set r = .Range(Cells(19, 3), Cells(28, 12))
r.CopyPicture Appearance:=xlScreen, Format:=xlBitmap
Set chtO = .ChartObjects.Add(1, 1, r.Width, r.Height)
End With
Here's the part that doesn't:
With chtO
Chart.Paste
Chart.Export FileName:=FileName, FilterName:="JPG" ' file name is created prior to this code
.Delete
' End With
To be more specific, the .Paste doesn't work. The chart is exported (though empty) and the chart is deleted.
One more thing, If I step through the code, it works. Any ideas?
Here's the code that works:
With ActiveSheet
Set r = .Range(Cells(19, 3), Cells(28, 12))
r.CopyPicture Appearance:=xlScreen, Format:=xlBitmap
Set chtO = .ChartObjects.Add(1, 1, r.Width, r.Height)
End With
Here's the part that doesn't:
With chtO
Chart.Paste
Chart.Export FileName:=FileName, FilterName:="JPG" ' file name is created prior to this code
.Delete
' End With
To be more specific, the .Paste doesn't work. The chart is exported (though empty) and the chart is deleted.
One more thing, If I step through the code, it works. Any ideas?