+ Reply to Thread
Results 1 to 3 of 3

Use alternative file if original file not available VBA EXCEL

Hybrid View

  1. #1
    Registered User
    Join Date
    11-14-2012
    Location
    Melbourne
    MS-Off Ver
    Excel 2007
    Posts
    3

    Question Use alternative file if original file not available VBA EXCEL

    Hello

    When a item is selected from a list box, I want to display an image in a picturebox which matches the the item selected. (Managed to do that).
    Then if that file is not available, I would like to call up another image to display instead. This is what I have so far. It displays the image if it is there but if it is not available nothing changes.

    Private Sub Listbox_Click()
    
    a = Listbox.Text
    On Error Resume Next
     Section_pic2.Picture = LoadPicture("G:\Design\clinton\Calculator\New Pictures\" & a & ".jpg")
    On Error GoTo 0
    If Section_pic2.Picture Is Nothing Then
    Section_pic2.Picture = LoadPicture("G:\Design\clinton\Calculator\New Pictures\No Image.jpg")
    End If
    End Sub
    Sorry if it is a bad post as this is my first.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,646

    Re: Use alternative file if original file not available VBA EXCEL

    I don't think Section_pic2 will ever be nothing.

    Why not try checking if the image file exists?
    Private Sub Listbox_Click()
    
       a = Listbox.Text
    
        If Len(Dir("G:\Design\clinton\Calculator\New Pictures\" & a & ".jpg"))<>0  Then    
               Section_pic2.Picture = LoadPicture("G:\Design\clinton\Calculator\New Pictures\" & a & ".jpg")
        Else 
               Section_pic2.Picture = LoadPicture("G:\Design\clinton\Calculator\New Pictures\No Image.jpg")
        End If
    
    End Sub
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    11-14-2012
    Location
    Melbourne
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Use alternative file if original file not available VBA EXCEL

    I forgot to reply! This worked great. Thanks!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1