Changing Images With VBA

Coach3131

Board Regular
Joined
Nov 23, 2007
Messages
242
I am trying to write a macro where I can change images for a picture file. I can do the insert method, but if I change pictures and run it again, it just inserts the next picture on top of it instead of changing the current image. Can anyone help here?
 
An alternative approach would be to leave all 5 images on the page and play with the visibility property, like

place the images on the sheet and give each image a "Name"

If Range("d9") = "Domestic" Then
Shapes("pic1").Visible = True
Shapes("pic2").Visible = False
End if

you can play with the if statement to turn the visibility of the images on and off depending on other cell conditions
 
Upvote 0

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Paul,

I just used 5 as an example. I would want to create reports where I can pick my report and swap out the images based on that. So, some will be static and some will be dynamic based on the report selection.
 
Upvote 0
Code:
Sub DeleteSomeNotAll() 
    For Each mypicture In ActiveSheet.Shapes 
        Select Case mypicture.Name 
        Case "Button 5", "Button 11", "Text Box 36", "Button 48"  '<----- Not to be deleted
             ' do nothing
        Case Else 
            mypicture.Delete 
        End Select 
    Next mypicture 
End Sub

This is how I do it. There might be, or certainly will be, better ways.

John
 
Upvote 0
Thanks John... I think I can do a variation between both suggestions... I can loop through a range and set all pictures to change as a variable.
 
Upvote 0

Forum statistics

Threads
1,224,618
Messages
6,179,919
Members
452,949
Latest member
beartooth91

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top