Macro Excel - Save image to chart export to directory and import to form

1

I upgraded my version of Office to 2016 and some macros stopped working properly. The routine when executed in isolation works properly, but when it goes into a process it stops working. The macro in question makes the following precedents. Copy a Range:

Set rng = .Range("S1:W4")
rng.CopyPicture xlScreen, xlBitmap 

Create a chart:

Set cht = .ChartObjects.Add(0, 0, rng.Width, rng.Height)

Paste the image into the graphic Exports the image in JPGEG format to a folder.

As informed, the routine works if used separately. But when I run the form, the routine stops working. The chart is exported but no image. The file size is also reduced.

    
asked by anonymous 18.08.2016 / 15:42

1 answer

2

I was able to identify the problem: In the previous version I copied the image of the range, created a graph with the dimensions of the range and directly pasted the image copied in the graphic.

The problem solved by including the cht.Activate command before the cht.Chart.Paste procedure.

    
19.08.2016 / 16:48