Excel 2016 Macro will not work correctly

bergy

Board Regular
Joined
Apr 23, 2002
Messages
115
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?
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off

Forum statistics

Threads
1,213,529
Messages
6,114,155
Members
448,554
Latest member
Gleisner2

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