ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   control gif with VB (https://www.excelbanter.com/excel-programming/342025-control-gif-vbulletin.html)

Christian Galbavy

control gif with VB
 
Hi!

I have three gif-objects (three smilies, one green, one yellow, one red)
which build a traffic light. Depending on the user interaction, I want to
display only one of the three smilies. Does anybody know, how I can handle
this problem. Is it possible to control gifs with VB, I mean control their
state (displayed/ not displayed) or is there something like a canvas, which
can contain a gif?

Thanks a lot for your answers.

Regards
Christian



Jake Marx[_3_]

control gif with VB
 
Hi Christian,

Christian Galbavy wrote:
I have three gif-objects (three smilies, one green, one yellow, one
red) which build a traffic light. Depending on the user interaction,
I want to display only one of the three smilies. Does anybody know,
how I can handle this problem. Is it possible to control gifs with
VB, I mean control their state (displayed/ not displayed) or is there
something like a canvas, which can contain a gif?


Are you referring to GIFs on a worksheet? If so, you can use the Shapes
collection to get at the images via VBA. Here's the setup:

1) Insert each GIF using Insert | Picture -- From File...

2) Name them picGreen, picYellow, and picRed (after selecting one, you can
use the Name box in the toolbar to rename it)

Now, you can show/hide them as follows:

Public Enum eLightColor
Green = 1
Yellow = 2
Red = 3
End Enum

Public Sub gChangeLight(rlColor As eLightColor)
With Sheets("Sheet1")
If rlColor = eLightColor.Green Then
.Shapes("picGreen").Visible = msoTrue
.Shapes("picYellow").Visible = msoFalse
.Shapes("picRed").Visible = msoFalse
ElseIf rlColor = eLightColor.Yellow Then
.Shapes("picGreen").Visible = msoFalse
.Shapes("picYellow").Visible = msoTrue
.Shapes("picRed").Visible = msoFalse
Else
.Shapes("picGreen").Visible = msoFalse
.Shapes("picYellow").Visible = msoFalse
.Shapes("picRed").Visible = msoTrue
End If
End With
End Sub

'/ make the light green
gChangeLight eLightColor.Green

--
Regards,

Jake Marx
www.longhead.com


[please keep replies in the newsgroup - email address unmonitored]




All times are GMT +1. The time now is 05:14 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com