• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Change Picture Source using VBA

kcm72

New Member
I have picture icons that I want to toggle between given a condition. Is there a way to programmatically do this using VBA?


ActiveSheet.Shapes.Range(Array("Image1")).Select


I thought I could simply change the attributes for the "Image1" object but no luck there.


Any help greatly appreciated.
 
Hi, kcm72!


First of all welcome to Chandoo's website Excel forums. Thank you for your joining us and glad to have you here.


As a starting point I'd recommend you to read the green sticky topics at this forums main page. There you'll find general guidelines about how this site and community operates (introducing yourself, posting files, netiquette rules, and so on).


Among them you're prompted to perform searches within this site before posting, because maybe your question had been answered yet.


Feel free to play with different keywords so as to be led thru a wide variety of articles and posts, and if you don't find anything that solves your problem or guides you towards a solution, you'll always be welcome back here. Tell us what you've done, consider uploading a sample file as recommended, and somebody surely will read your post and help you.


And about questions in general...


If you haven't performed yet the search herein, try going to the topmost right zone of this page (Custom Search), type the keywords used in Tags field when creating the topic or other proper words and press Search button. You'd retrieve many links from this website, like the following one(s) -if any posted below-, maybe you find useful information and even the solution. If not please advise so as people who read it could get back to you as soon as possible.


And about this question in particular...


Give a look at this link, maybe you could extract any useful idea from it:

http://chandoo.org/forums/topic/insert-photos-in-excel-upon-name-change-in-a-cell


Regards!
 
Thanks - This looks like it will work but is there another way to manipulate pictures in Excel without using the Comment object? My initial search isn't returning much. I'll continue looking.


Maybe something with control objects? Picture Format options - change picture source?


Thanks
 
Hi, kcm72!


Give a look at this file:

https://dl.dropboxusercontent.com/u/60558749/Change%20Picture%20Source%20using%20VBA%20%28for%20kcm72%20at%20chandoo.org%29.rar


This is the VBA code for the cyan button:

-----

[pre]
Code:
Option Explicit

Private Sub cmdShuffle1_Click()
' constants
Const ksPath = "iPeperePhotos"
' declarations
Dim I As Integer, J As Integer
' start
Randomize
' process
For I = 1 To 4
J = Int(Rnd() * 4) + 1
Select Case I
Case 1
imgControl1.Picture = LoadPicture("")
imgControl1.Picture = LoadPicture(ksPath & Cells(J, 1).Value)
Case 2
imgControl2.Picture = LoadPicture("")
imgControl2.Picture = LoadPicture(ksPath & Cells(J, 1).Value)
Case 3
imgControl3.Picture = LoadPicture("")
imgControl3.Picture = LoadPicture(ksPath & Cells(J, 1).Value)
Case 4
imgControl4.Picture = LoadPicture("")
imgControl4.Picture = LoadPicture(ksPath & Cells(J, 1).Value)
End Select
Next I
' end
End Sub
[/pre]
-----


Just advise if any issue.


Regards!
 
Back
Top