Import and Rename Picture in Excel 07

Unclechawie

New member
Joined
Jun 24, 2013
Messages
5
Reaction score
0
Points
0
I'm working on an application that will add a picture based on a series of previous selections. The selection culminate in the name of the image I need in cell c67 of sheet "Info". It then pastes it at cell a15 of sheet "Setup" Here is the code for pulling in the picture.

Code:
Filename = Filepath & info.Range("c67") & ".jpg"
With setup.Range("a15")
    Set pic = setup.Shapes.AddPicture(Filename, msoFalse, msoTrue, .Left, .Top, 300, 240)
End With

What I'm having trouble with is a way to automatically change the name of the newly embedded picture so as to be able to manipulate it. My desire is that each time a dropdown selection is made from the dropdown menu in question, it will delete the previous photo and make the new one appear. The last selection is to be kept for later usage in the application. My first thought is just to code a macro to search every shape name until it finds the only one with "Picture" in the name. I'm not quite sure how to do that though. All thoughts and suggestions are much appreciated.

Charles
 
Ok, so I've kept at it a little, but am still stuck.

Code:
Dim Rshape as shape
for each rshape in setup.shapes
    if rshape.name = "picture *" then
    [COLOR=#ff0000]rshape.name = info.range("c67")[/COLOR]
    end if
next rshape

This coding enable me to find the shape in question as it will be the only one with a name that starts with Picture. The code in red however is not functioning. When I check the image, it is still name Picture X.

Thoughts?
 
Ok, so got it figured out. Need the code to read:

Code:
Dim Rshape as shape
for each rshape in setup.shapes
    if rshape.name Like "Picture *" then
    [COLOR=#ff0000]rshape.name = info.range("c67")[/COLOR]
    end if
next rshape

When I switched the "=" to "Like" per a suggestion from Tom Ogilvy at allexperts.com it didn't change anything at all. However, when I capitalized the "p" in "Picture" voila, everything was good to go. Not sure exactly why but apparently it had to be case sensitive.
 
Back
Top