Macro to Add Default Picture if Picture is not Detected

I want to be able to add a default picture when a macro is run if there is not a picture already present. I have an excel file that asks for an image and positions it within a cell. I have a button that inserts the picture and names it as "ImagePicture". Now, the picture is not mandatory to be added but I would still like to add a default picture of a symbol to serve as a placeholder.
bbarreneAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

kittenwhiskyCommented:
this code checks if a shape called "ImagePicture" already exists, if not, it inserts a default picture and names it "ImagePicture"
Sub InsertDefaultPicture()

Dim ImagePicture As Picture, DefaultPicturePath As String

'Default picture path
'change as appropriate
DefaultPicturePath = "C:\Users\Public\Pictures\DefaultPicture.jpg"

'test if ImagePicture already exists in sheet
On Error Resume Next
    Set ImagePicture = ActiveSheet.Shapes("ImagePicture")
On Error GoTo 0

'if ImagePicture doesn't exist, insert default Picture
If ImagePicture Is Nothing Then
    Set ImagePicture = ActiveSheet.Pictures.Insert(DefaultPicturePath)
    ImagePicture.Name = "ImagePicture"
End If

End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
bbarreneAuthor Commented:
Thanks for the help.
0
bbarreneAuthor Commented:
I needed to change the first code below to the second code below in order for it to work.

Thanks for the help.


Dim ImagePath as Picture

Dim Image Path as Object

Open in new window

0
bbarreneAuthor Commented:
Whoops. I meant
Dim ImagePicture as Picture 

Dim ImagePicture as Object

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.