View Full Version : [SOLVED:] ADDING INDICATOR ICONS TO EXCEL USERFORM
DeanP
12-20-2018, 06:53 AM
Is it possible to have indicators, similar to the indicator icons in conditional formatting, in my userform? I am
Thinking of something like a red/green traffic light, with the red light turning green when a task has successfully
been completed.
Would appreciate if anyone could point me to some kind of resource I can look at or somewhere I can research how
to do this.
waimea
12-20-2018, 07:04 AM
Perhaps you could use an image and enable or disable the visible property of the image that you want to show?
Go to View -> Toolbox -> Insert image
Change the background to transparent, the border to none and the visibility to true.
Then in your code, change the visibility of the icon/indicator you want to show.
Ex. in the start of your sub you can set the red light image to be visible and at the end of the macro you hide the red light image and show the green light image.
DeanP
12-20-2018, 08:47 AM
Hey - thanks for your suggestion. I will definitely look into
Paul_Hossler
12-20-2018, 09:55 AM
I think RYG traffic light icons would too small to highlight. I went to
https://www.iconsdb.com/red-icons/circle-icon.html
to get 32x32 ico files. There's many other colors and shapes
This is just example of cycling Red-Yellow-Green-Blue for each of 4 steps
23448
Option Explicit
Dim iStep As Long
Dim aryColors(1 To 4) As String
Private Sub UserForm_Initialize()
With Me
.Height = 260 ' hides ico's on bottom half
Call SetIcon(1, "R")
Call SetIcon(2, "R")
Call SetIcon(3, "R")
Call SetIcon(4, "R")
End With
iStep = 1
End Sub
Private Sub CommandButton1_Click()
If aryColors(iStep) = "B" Then
iStep = iStep + 1
If iStep = 5 Then
Me.Hide
Unload Me
End If
End If
Call SetIcon(iStep, "")
End Sub
Private Sub SetIcon(i As Long, c As String)
If Len(c) = 0 Then
Select Case aryColors(i)
Case "B"
aryColors(i) = "R"
Case "R"
aryColors(i) = "Y"
Case "Y"
aryColors(i) = "G"
Case "G"
aryColors(i) = "B"
End Select
Else
aryColors(i) = UCase(c)
End If
With Me
Select Case aryColors(i)
Case "R"
Set .Controls("Image" & i).Picture = .Red.Picture
Case "Y"
Set .Controls("Image" & i).Picture = .Yellow.Picture
Case "G"
Set .Controls("Image" & i).Picture = .Green.Picture
Case "B"
Set .Controls("Image" & i).Picture = .Blue.Picture
End Select
End With
End Sub
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.