Image File Errors - Trapping them with VBA

kevin.philips

Active Member
Joined
Jan 7, 2003
Messages
364
Hi,

I'm struggling on this one and hope you can help...!

I have a form that contains a ListView and an Image control. I have the image control changing its LoadPicture property depending on what has been clicked in the ListView, now this works beautifully when the file exists but generates a path not found error when it doesn't, is there an easier way other than invoking a filesystem search to see if the file is available prior to setting the LoadPicture property...?

Best Regards

kevin
 

Some videos you may like

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,062
Office Version
  1. 365
Platform
  1. Windows
kevin

You can use Dir to see if a file exists.
Code:
If Dir("C:\MyImage.jpg")<>"" Then
   MsgBox "File exists."
Else
   MsgBox "File doesn't exist."
End If
 

Watch MrExcel Video

Forum statistics

Threads
1,118,850
Messages
5,574,647
Members
412,607
Latest member
caner
Top