Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Loadpicture - check if file exists

Hi friends,

I have a picture box (image1) and I use loadpicture to fill it with a
jpg image. The path is created in a cell from information inserted by
the user. The jpg images (some thousands!) are stored in a folder in
C:\. Everything works fine but there is one problem. In some occasions
it is normal for my application to call an image that is not yet
created. In that case I get error 53 'file not found'. I need a
condition to check if the file requested by the user exists. If this
condition is TRUE then my code works. If it is False I need it to
ignore the user's request. Please help me if you can.

Here is one part of my code

For i = 1 To 10


If Range("code").Offset(i - 1, 0).Value < blank Then
filename(i) = Range("filename").Offset(i - 1, 0).Value
image(i).Picture = LoadPicture(filename(i))
Else
image(i).Picture = LoadPicture("c:\Photos\blank.jpg")

End If

Next i

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,117
Default Loadpicture - check if file exists

tony - change code to this:
For i = 1 To 10


on error resume next
If Range("code").Offset(i - 1, 0).Value < blank Then
filename(i) = Range("filename").Offset(i - 1, 0).Value
image(i).Picture = LoadPicture(filename(i))
Else

msgbox "Sorry, that picture is not available"

End If


i think this should work, or at least point you in the right direction.
susan, not-a-guru


t0ny wrote:
Hi friends,

I have a picture box (image1) and I use loadpicture to fill it with a
jpg image. The path is created in a cell from information inserted by
the user. The jpg images (some thousands!) are stored in a folder in
C:\. Everything works fine but there is one problem. In some occasions
it is normal for my application to call an image that is not yet
created. In that case I get error 53 'file not found'. I need a
condition to check if the file requested by the user exists. If this
condition is TRUE then my code works. If it is False I need it to
ignore the user's request. Please help me if you can.

Here is one part of my code

For i = 1 To 10


If Range("code").Offset(i - 1, 0).Value < blank Then
filename(i) = Range("filename").Offset(i - 1, 0).Value
image(i).Picture = LoadPicture(filename(i))
Else
image(i).Picture = LoadPicture("c:\Photos\blank.jpg")

End If

Next i


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Loadpicture - check if file exists

Hi t0ny

You can use Dir in your code to check if a file exist

If Dir(filename(i)) < "" Then

--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"t0ny" wrote in message ups.com...
Hi friends,

I have a picture box (image1) and I use loadpicture to fill it with a
jpg image. The path is created in a cell from information inserted by
the user. The jpg images (some thousands!) are stored in a folder in
C:\. Everything works fine but there is one problem. In some occasions
it is normal for my application to call an image that is not yet
created. In that case I get error 53 'file not found'. I need a
condition to check if the file requested by the user exists. If this
condition is TRUE then my code works. If it is False I need it to
ignore the user's request. Please help me if you can.

Here is one part of my code

For i = 1 To 10


If Range("code").Offset(i - 1, 0).Value < blank Then
filename(i) = Range("filename").Offset(i - 1, 0).Value
image(i).Picture = LoadPicture(filename(i))
Else
image(i).Picture = LoadPicture("c:\Photos\blank.jpg")

End If

Next i

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Loadpicture - check if file exists

Thank a lot. You saved me from a lot of trouble!

Happy new year


Ï/Ç Susan Ýãñáøå:
tony - change code to this:
For i = 1 To 10


on error resume next
If Range("code").Offset(i - 1, 0).Value < blank Then
filename(i) = Range("filename").Offset(i - 1, 0).Value
image(i).Picture = LoadPicture(filename(i))
Else

msgbox "Sorry, that picture is not available"

End If


i think this should work, or at least point you in the right direction.
susan, not-a-guru


t0ny wrote:
Hi friends,

I have a picture box (image1) and I use loadpicture to fill it with a
jpg image. The path is created in a cell from information inserted by
the user. The jpg images (some thousands!) are stored in a folder in
C:\. Everything works fine but there is one problem. In some occasions
it is normal for my application to call an image that is not yet
created. In that case I get error 53 'file not found'. I need a
condition to check if the file requested by the user exists. If this
condition is TRUE then my code works. If it is False I need it to
ignore the user's request. Please help me if you can.

Here is one part of my code

For i = 1 To 10


If Range("code").Offset(i - 1, 0).Value < blank Then
filename(i) = Range("filename").Offset(i - 1, 0).Value
image(i).Picture = LoadPicture(filename(i))
Else
image(i).Picture = LoadPicture("c:\Photos\blank.jpg")




End If

Next i


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Check if file exists Jon Excel Discussion (Misc queries) 14 October 4th 07 04:57 PM
Check if file exists / open it Gert-Jan Excel Programming 2 August 28th 06 04:20 PM
How do I check if a sheetname exists in a file? NezRhodes Excel Programming 2 August 22nd 06 09:44 AM
How to check if a file exists in an ftp folder LL Cool A Excel Discussion (Misc queries) 3 May 16th 06 09:22 PM
check if file exists Curt Excel Programming 0 December 7th 05 05:02 PM


All times are GMT +1. The time now is 10:50 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"