Consulting

Results 1 to 4 of 4

Thread: ADDING INDICATOR ICONS TO EXCEL USERFORM

  1. #1
    VBAX Regular
    Joined
    Nov 2018
    Location
    London, U.K.
    Posts
    99
    Location

    ADDING INDICATOR ICONS TO EXCEL USERFORM

    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.

  2. #2
    VBAX Contributor
    Joined
    Jul 2018
    Posts
    174
    Location
    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.
    Last edited by waimea; 12-20-2018 at 07:27 AM.

  3. #3
    VBAX Regular
    Joined
    Nov 2018
    Location
    London, U.K.
    Posts
    99
    Location
    Hey - thanks for your suggestion. I will definitely look into

  4. #4
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,726
    Location
    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

    Capture.JPG

    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
    Attached Files Attached Files
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •