Consulting

Results 1 to 15 of 15

Thread: Invalid image error :481

  1. #1

    Invalid image error :481

    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?

  2. #2
    VBAX Expert Logit's Avatar
    Joined
    Sep 2016
    Posts
    606
    Location
    .
    Does changing this line of code work :

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



  3. #3
    Quote Originally Posted by Logit View Post
    .
    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

  4. #4
    VBAX Newbie
    Joined
    Oct 2018
    Posts
    3
    Location
    Following... sharing solution would be appreciated

  5. #5
    I still do not have any solution for this problem.It is a non solved thread in many forums.

  6. #6
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,711
    Location
    Quote Originally Posted by djemy1975 View Post
    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


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  7. #7
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,711
    Location
    This seems to save the chart and put on userform

    Capture.JPG


    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
    Attached Files Attached Files
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  8. #8
    Quote Originally Posted by Paul_Hossler View Post
    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.

  9. #9
    Quote Originally Posted by Paul_Hossler View Post
    This seems to save the chart and put on userform

    Capture.JPG


    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.

  10. #10
    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.
    Attached Files Attached Files

  11. #11
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,711
    Location
    It works for me with either of these

    Me.Image1.Picture = LoadPicture(Fname)
    or

    Userform1.Image1.Picture = LoadPicture(Fname)
    Capture.JPG
    Attached Files Attached Files
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  12. #12
    Quote Originally Posted by Paul_Hossler View Post
    It works for me with either of these

    Me.Image1.Picture = LoadPicture(Fname)
    or

    Userform1.Image1.Picture = LoadPicture(Fname)
    Capture.JPG
    It still gives the same error
    Attached Images Attached Images

  13. #13

  14. #14
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,711
    Location
    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
    Attached Files Attached Files
    Last edited by Paul_Hossler; 11-06-2018 at 09:21 AM.
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  15. #15
    Quote Originally Posted by Paul_Hossler View Post
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •