Results 1 to 3 of 3

Thread: Load PNG File in Userform Image Control

  1. #1
    Junior Member
    Join Date
    Oct 2012
    Posts
    26
    Rep Power
    0

    Load PNG File in Userform Image Control

    Gents,

    I use a image control to load an exported image. When i use the gif or jpg i have no problems. But as soon i want to import the png file format it gives an error. When i use a Image1 and try loading a png through the image propertys it give the message invalid file.

    I export the gif with a transparent background but the quality is realy poor thats why i want to use PNG


    Code:
    Private Sub UpdateChart()
        Dim Fname As String
        Dim i As Integer
        
        
    Application.ScreenUpdating = False
        
        For i = 1 To 3
            Sheets("DASHBOARD").ChartObjects(i).Activate
            ActiveChart.Parent.Width = 400
            ActiveChart.Parent.Height = 180
        
        '   Save chart as GIF
            Fname = ThisWorkbook.Path & Application.PathSeparator & i & "_temp.gif"
            ActiveChart.Export FileName:=Fname, FilterName:="GIF"
            Me.Controls("Image" & i).Picture = LoadPicture(Fname)
            
            Application.ScreenUpdating = True
        Next
    End Sub

  2. #2
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,402
    Rep Power
    10
    Did you try changing the file extension to .png and keep the filter as GIF

    Code:
    Fname = ThisWorkbook.Path & Application.PathSeparator & i & "_temp.png"
    A dream is not something you see when you are asleep, but something you strive for when you are awake.

    It's usually a bad idea to say that something can't be done.

    The difference between dream and aim, is that one requires soundless sleep to see and the other requires sleepless efforts to achieve

    Join us at Facebook

  3. #3
    Administrator Admin's Avatar
    Join Date
    Mar 2011
    Posts
    1,123
    Rep Power
    10
    Hi EF,

    Does the PNG extension working for you ?

    I do get error while uploadng PNG files. I'm using Excel 2010 on WIN 7.
    Cheers !

    Excel Range to BBCode Table
    Use Social Networking Tools If You Like the Answers !

    Message to Cross Posters

    @ Home - Office 2010/2013/2016 on Win 10 (64 bit); @ Work - Office 2016 on Win 10 (64 bit)

Similar Threads

  1. Populate Ribbon Controls On Load Dynamically Through VBA Variables
    By phxpoolplayer in forum Excel Ribbon and Add-Ins
    Replies: 1
    Last Post: 04-20-2013, 01:51 AM
  2. Runtime Error 481 invalid figure when PNG
    By Tony in forum Excel Help
    Replies: 0
    Last Post: 02-12-2013, 12:59 AM
  3. Adding Scroll bar to image box in vba
    By princ_wns in forum Excel Help
    Replies: 1
    Last Post: 12-13-2011, 09:47 PM
  4. Replies: 1
    Last Post: 06-02-2011, 10:38 AM
  5. FreezePane In A Userform SpreadSheet Control 11.0
    By Excel Fox in forum Excel and VBA Tips and Tricks
    Replies: 0
    Last Post: 05-15-2011, 05:49 AM

Posting Permissions

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