Hi everyone,
I've got something that doesn't work like it should
Public Function Picture_2_File(myImage As Variant) As String Dim Ans As String, sPath As String Dim rng As Range Dim oCht As ChartObject Dim oPic As Object On Error Resume Next Kill ThisWorkbook.Path & "Temp.gif" Set oPic = ThisWorkbook.Worksheets("INTRO").Shapes(myImage) Err.Clear oPic.Copy sPath = ThisWorkbook.Path & "Temp.gif" Set oCht = ActiveSheet.ChartObjects.Add(100, 0, oPic.Width, oPic.Height) oCht.Chart.Paste oCht.Chart.Export sPath oCht.Delete Set oCht = Nothing Err.Clear On Error GoTo 0 Picture_2_File = sPath End Function
The worksheet where the images are stored is named "INTRO" and i've got pictures
myImgae will contain the picture name of the one that I want to create as image file to import in a Userform (I chose for gif as extension but the same happens with jpg or bmp)
If I run the code the temp.gif is created but the content is blank
If I run the macro and interupt it at the before tha Paste command is exceuted and then go though it step by step (F8) it works and the temp.gif is the picture.
I tried adding a wait state (more than one) but that doesn't make it work.
Any suggestions? I'm using Excel 2021 and the worksheets are unportected etc etc.
Thanks in advance
Try adding oCht.Activate before the Paste line.
And so simple, I knew it must be something like that.
Great, thanks.