PDA

View Full Version : Workign with Image - Should be Simple?



russellhq
10-26-2007, 02:54 AM
Excel 2003. I've a worksheet with several images on it, with one main image.

When I click a command button, I want the main image to change to whatever image the command button is coded to. The following works when command button "Simple3" is clicked. The main image, "Image1" now looks like "Image4".

Private Sub Simple3_Click()
Image1.Picture = Image4.Picture
End Sub

My problem is, I want to expand the code so that the main image is changed based on a user input.

e.g.

Private Sub Stuck_Click()
MyImage = InputBox("image name?")
Image1.Picture = MyImage.Picture
End Sub

I've tried:

Private Sub Stuck_Click()
MyImage = InputBox("image name?")
Image1.Picture = Shapes(MyImage).Picture
End Sub

Does not work either.

I think there should be a simple solution, but being new to this I cannot find it :(

Bob Phillips
10-26-2007, 03:34 AM
Private Sub Stuck_Click()
MyImage = InputBox("image name?")
Image1.Picture = Activesheet.Pictures(MyImage).Picture
End Sub

russellhq
10-26-2007, 03:38 AM
I get the following error when it tries to execute the code:



Run-time error '438':

Object doesn't support this property or method.



Doh!

Bob Phillips
10-26-2007, 03:40 AM
Doesn't look like the object retains its source, it gets embedded.

russellhq
10-26-2007, 03:43 AM
Doesn't look like the object retains its source, it gets embedded.

Not sure what this means, but is there a way around it?

I want to store the image files in the workbook and not locally as a file.

Bob Phillips
10-26-2007, 07:17 AM
The way I have done this sort of thing is to store the images off screen, and then move the slecetd ones into view, and move any others off view.