0
I have to import 3 charts for a userform. I had even managed, but suddenly started to give errors, then I put the code "On Error Resume Next" (but this is not solution, just does not lock my form anymore, but does not do what should do). At the moment I have the code below:
Sheets("Plan3").Select
On Error Resume Next
Set Grafico = Sheets("Plan3").ChartObjects("Graf").Chart
nome = "C:\Windows\Temp" & Application.PathSeparator & "temp.gif"
Grafico.Export Filename:=nome, Filtername:="GIF"
Imagem1.Picture = LoadPicture(nome)
Sheets("Historico").Select
On Error Resume Next
Set Grafico = Sheets("Historico").ChartObjects("Grafi").Chart
nome = "C:\Windows\Temp" & Application.PathSeparator & "temp.gif"
Grafico.Export Filename:=nome, Filtername:="GIF"
Imagem2.Picture = LoadPicture(nome)
Sheets("KalosG1").Select
On Error Resume Next
Set Grafico = Sheets("KalosG1").ChartObjects("Grafic").Chart
nome = "C:\Windows\Temp" & Application.PathSeparator & "temp.gif"
Grafico.Export Filename:=nome, Filtername:="GIF"
Imagem3.Picture = LoadPicture(nome)
Note: I put "Sheets("...."). Select" before each "On Error Resume Next" to try to solve, but it did not work. Ps: there are hours that work have hours that do not. Sometimes only one of the graphics fails... I have no idea what is wrong.
Instead of ignoring the error (which is what the command
On Error Resume Next
) makes, fix the error! If the error is occurring, it is because some problem exists. Without you post what is this error, it is impossible for anyone to help you.– Luiz Vieira
Put the code snippet in a Try / catch block, take the Exception message and click here.
– Marcell Alves
Good morning Luiz Vieira. I took the "On error Resume Next" and the error that appeared was: Error at runtime '481': Invalid figure
– Clebson Omena
Good morning Marcell Alves. Boy, I’m sorry for the ignorance, but I know if I know what this block would be Try / catch. However the error that appeared was: Runtime error '481': Invalid figure
– Clebson Omena
Just to be sure, the "c: windows temp" directory exists, right? Also, the charts and spreadsheets are with the correct names, right? I ask because this error indicates that the
LoadPicture
is failing, which could mean that the previous code failed to save the figure with the chart.– Luiz Vieira
Good afternoon Luiz Vieira. Yes. At first it’s all right (so much so that the error is not continuous... There are hours that occurs and hours that do not)... Ps: a guy said that this is a kind of "bug" (he didn’t say exactly that) from the office itself. Dai he suggested by: "Grafico.Parent.Select " below the part: name = "C: Windows Temp" & Application.Pathseparator & "temp.gif" ... Well, it seems to have worked, since yesterday that no more failure.
– Clebson Omena