Current Code:
Const cName = "ChartDummy"
Const rName = "Availability"
Const iconSource = "C:\user.name\defaulfolder\"
'/* Availability is a named Range for this example but can be any valid range */
'/* UF_EmoTrans is a Userform with and Image Control named I_Console */
Dim oCh As ChartObject, chImg As String
Dim Ch As Object
Application.DisplayAlerts = False
With Sheet2
'.Activate
chImg = iconSource & "availIcon.jpg"
Set oCh = .ChartObjects.Add(370, 14, 180, 277.2): oCh.Name = cName
.Range(rName).CopyPicture xlScreen, xlBitmap
'oCh.Activate
oCh.Chart.Paste
oCh.Chart.Export chImg, "JPG"
'/* I call this procedure at UserForm_Initialize */
UF_EMOTrans.I_Console.Picture = LoadPicture(chImg)
oCh.Delete
End With
My current code works when I run it in break mode (using F8 and stepping through each line).
It exports the Range as image(through chartobject) and loads it to the userform just fine.
Now, when I run this in execution mode (loading the form), it doesn't create the same result.
It seems the oCh.Chart.Paste
method didn't fire and so no image was paste within the chart.
Once exported, it produces a picture with plain white background.
So my question is, why is that? Why does it behave differently?
P.S.:
It will work if the chart is activated (but you will need to activate the sheet first) prior pasting (commented lines).
But I just want to know if this is one of those oddities that Excel have that we just have to live with.