HOW TO: Check if a picture exists?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have the followinf code

Set picDB = ws.Pictures("DB_LOGO_1")

but if the worksheet does not contain the logo then I get an error,
therefore how can I check if the picture exists before I try to set picDB to
it?

TIA
KM
 
On Error Resume Next
Set picDB = ws.Pictures("DB_LOGO_1")
If picDB is Nothing Then
'Does Not Exist
End If
On Error Goto 0

Charles
 
Thats just cheesy coding

Die_Another_Day said:
On Error Resume Next
Set picDB = ws.Pictures("DB_LOGO_1")
If picDB is Nothing Then
'Does Not Exist
End If
On Error Goto 0

Charles
 
Gee glad to be of help....

anyhow you can also loop through them and test the name of all pictures
but that is not very efficient if you have a lot of pictures.

Sub FindPic()
Dim pic1
For Each pic1 In ws.Pictures
If pic1.Name = "DB_LOGO_1" Then _
Set picDB = pic1
Next

Charles

P.S. What's with all the rude posters lately?
 
There's nothing with using the information returned from an error. That's
why you are given the chance to examine the error and decide how you wish to
proceed.
What would be your "non-cheesy" solution ?

NickHK
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top