I need to export grouped shapes named 'center' to a share folder as .jpg.
I have code that does the job if using keyboard button f8.
If code runs as normal it exports a blank picture.
Sub Export_JPG()
Dim ws1 As Worksheet: Set ws1 = Worksheets("KPI")
Dim ws2 As Worksheet: Set ws2 = Worksheets("ChartPage")
Dim chtObj As ChartObject
Dim SharepointAddress As String
Dim myshape As shape
ws1.Range("A1").FormulaR1C1 = "=NOW()"
Set myshape = ws1.Shapes("center")
Set chtObj = ws2.ChartObjects.Add(myshape.Left, myshape.Top, myshape.Width, myshape.Height)
myshape.CopyPicture
chtObj.Chart.Paste
SharepointAddress = "C:\Users\me\Desktop\1.jpg"
Kill SharepointAddress
chtObj.Chart.Export Filename:=SharepointAddress, Filtername:="JPG"
chtObj.Delete
Set chtObj = Nothing
End Sub
Please insert a line between CopyPicture
and Paste
:
myshape.CopyPicture
chtObj.Select
chtObj.Chart.Paste 'it works only for a selected chart!