CustomX
CustomX

Reputation: 10113

Excel VBA - If condition on image

I have added my macro to my toolbar and would like to put some sort of basic check on it. Instead of asking the user whether he wants to perform the macro, I would like to check the document for a certain image that is always in the documents the macro is used for. (other suggestions are welcome too)

ActiveSheet.Shapes.Range(Array("Picture -767")).Select

That's the code I use to select the image. I haven't been able to find out how to manage an image. What I'm trying to do is

If Image is found then
    Part1
    Part2
Else
    MsgBox 'Macro is not intended for this document'
End if

All help is appreciated!

Upvotes: 0

Views: 1565

Answers (1)

Jerry Beaucaire
Jerry Beaucaire

Reputation: 3197

This should work:

Option Explicit

Sub PicTest()
Dim Shp As Shape

    On Error GoTo ErrorExit
    Set Shp = ActiveSheet.Shapes("Picture -767")
    On Error GoTo 0

    ActiveSheet.Shapes.Range(Array("Picture -767")).Select
    Part1
    Part2
    Exit Sub

ErrorExit:
    MsgBox "Macro is not intended for this sheet"
End Sub

Upvotes: 1

Related Questions