PDA

View Full Version : [SOLVED] Invalid image error :481



djemy1975
10-16-2018, 08:01 AM
Dear friends,
Please be kindly requested to help me get over a problem in displaying charts (7 charts)as images in my userform .The problem is when navigating from image to image by using next and previous buttons I get this error "Invalid image 481" error and when debugging the cursor comes over this line:
Image1.Picture = LoadPicture(Fname)" and highlited with yellow colour.

My function is as follows:

Private Sub SaveChart() Dim MyChart As Chart
Dim Fname As String


Set MyChart = Sheets("Charts").ChartObjects(ChartNum).Chart
'MyChart.Parent.Width = 400
'MyChart.Parent.Height = 350

Fname = ThisWorkbook.Path & Application.PathSeparator & "temp.gif"
MyChart.Export Filename:=Fname, FilterName:="GIF"



' Show the chart
Image1.Picture = LoadPicture(Fname)


End Sub

Could someone tell me where is the error I have done?

Logit
10-16-2018, 12:32 PM
.
Does changing this line of code work :

Change existing to : Fname = ThisWorkbook.Path & "\temp.gif"

djemy1975
10-16-2018, 01:39 PM
.
Does changing this line of code work :

Change existing to : Fname = ThisWorkbook.Path & "\temp.gif"





I tested it but it gives the same error.thank you though

controz
11-01-2018, 11:44 PM
Following... sharing solution would be appreciated

djemy1975
11-04-2018, 03:52 AM
I still do not have any solution for this problem.It is a non solved thread in many forums.

Paul_Hossler
11-04-2018, 07:56 AM
I still do not have any solution for this problem.It is a non solved thread in many forums.

Does this mean that you're asked the same question in other forums and forgot to include that information and the other links here?

Paul_Hossler
11-04-2018, 08:13 AM
This seems to save the chart and put on userform

23132




Option Explicit

Sub SaveChart()
Dim MyChart As Chart
Dim Fname As String

Set MyChart = Sheets("Chart1")
'MyChart.Parent.Width = 400
'MyChart.Parent.Height = 350

Fname = ThisWorkbook.Path & Application.PathSeparator & "temp.gif"
MyChart.Export Filename:=Fname, FilterName:="GIF"


' Show the chart
Load UserForm1
UserForm1.Image1.Picture = LoadPicture(Fname)
UserForm1.Show
End Sub

djemy1975
11-04-2018, 08:14 AM
Does this mean that you're asked the same question in other forums and forgot to include that information and the other links here?
I have already asked the same question in other forums and got nothing as answer.Could someone try to figure out the source of this problem.

djemy1975
11-04-2018, 08:18 AM
This seems to save the chart and put on userform

23132




Option Explicit

Sub SaveChart()
Dim MyChart As Chart
Dim Fname As String

Set MyChart = Sheets("Chart1")
'MyChart.Parent.Width = 400
'MyChart.Parent.Height = 350

Fname = ThisWorkbook.Path & Application.PathSeparator & "temp.gif"
MyChart.Export Filename:=Fname, FilterName:="GIF"


' Show the chart
Load UserForm1
UserForm1.Image1.Picture = LoadPicture(Fname)
UserForm1.Show
End Sub



Actually I am at work.I will give it a try when I will be at home and give you feedback.Thanks for your quick support.

djemy1975
11-06-2018, 07:12 AM
To better understand my problem ,I decided to attach a sample of my workbook so that you can help me.Please do not refresh charts because I have already deleted tables.Use only next previous buttons to get the error.

Paul_Hossler
11-06-2018, 08:08 AM
It works for me with either of these



Me.Image1.Picture = LoadPicture(Fname)


or




Userform1.Image1.Picture = LoadPicture(Fname)


23159

djemy1975
11-06-2018, 08:16 AM
It works for me with either of these



Me.Image1.Picture = LoadPicture(Fname)


or




Userform1.Image1.Picture = LoadPicture(Fname)


23159


It still gives the same error

djemy1975
11-06-2018, 08:21 AM
23162

Paul_Hossler
11-06-2018, 08:41 AM
https://www.mrexcel.com/forum/excel-questions/808744-exporting-chart-via-vba-sometimes-gives-empty-file.html

Post #7 talks about using .Activate


This seems reliable



Option Explicit


Private Sub Workbook_Open()
Dim FName As String

FName = ThisWorkbook.Path & Application.PathSeparator & "temp.gif"
On Error Resume Next
Kill FName
On Error GoTo 0
UserForm1.Show
End Sub







Private Sub UpdateChart()
Dim FName As String

Set currentchart = Sheets("Charts").ChartObjects(ChartNum).Chart
currentchart.Parent.Activate

'currentchart.Parent.Width = 300
'currentchart.Parent.Height = 150

' Save chart as GIF
FName = ThisWorkbook.Path & Application.PathSeparator & "temp.gif"
On Error Resume Next
Kill FName
On Error GoTo 0

currentchart.Export Filename:=FName, FilterName:="GIF"
' Show the chart
Image1.Picture = LoadPicture(FName)
Kill FName
End Sub

djemy1975
11-08-2018, 12:47 AM
https://www.mrexcel.com/forum/excel-questions/808744-exporting-chart-via-vba-sometimes-gives-empty-file.html

Post #7 talks about using .Activate


This seems reliable



Option Explicit


Private Sub Workbook_Open()
Dim FName As String

FName = ThisWorkbook.Path & Application.PathSeparator & "temp.gif"
On Error Resume Next
Kill FName
On Error GoTo 0
UserForm1.Show
End Sub







Private Sub UpdateChart()
Dim FName As String

Set currentchart = Sheets("Charts").ChartObjects(ChartNum).Chart
currentchart.Parent.Activate

'currentchart.Parent.Width = 300
'currentchart.Parent.Height = 150

' Save chart as GIF
FName = ThisWorkbook.Path & Application.PathSeparator & "temp.gif"
On Error Resume Next
Kill FName
On Error GoTo 0

currentchart.Export Filename:=FName, FilterName:="GIF"
' Show the chart
Image1.Picture = LoadPicture(FName)
Kill FName
End Sub


Thank you so much for the importance you have shown to my problem.It is working now like a charm .I am very grateful for this forum and especially Mr Paul .I will mark this thread "Solved" .Thanks again