Results 1 to 6 of 6

Thread: reduce _click events

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2004
    Location
    Lucenec, Slovakia
    Posts
    154

    Lightbulb reduce _click events

    Hi guys,

    I am creating an useform, where I have more then 60 labels.
    I do not want to write 56-times the below written code and everywhere change number of label. Is it possible instead of this make one macro?

    VB Code:
    1. Private Sub Label1_Click()
    2. UserForm1.Controls(labelname).SpecialEffect = fmSpecialEffectFlat
    3. labelname = "label1"
    4. UserForm1.Label1.SpecialEffect = fmSpecialEffectSunken
    5.  
    6. GetRGB UserForm1.Label1.BackColor, Red, Green, Blue
    7. RGBToHSL
    8. UserForm1.TextBox4.Value = Red
    9. UserForm1.TextBox5.Value = Green
    10. UserForm1.TextBox6.Value = Blue
    11. UserForm1.TextBox1.Value = H
    12. UserForm1.TextBox2.Value = S
    13. UserForm1.TextBox3.Value = L
    14. UserForm1.SpinButton1.Value = H
    15. UserForm1.SpinButton2.Value = S
    16. UserForm1.SpinButton3.Value = L
    17. UserForm1.SpinButton4.Value = Red
    18. UserForm1.SpinButton5.Value = Green
    19. UserForm1.SpinButton6.Value = Blue
    20. UserForm1.Label63.BackColor = UserForm1.Label1.BackColor
    21. End Sub

    Boris

  2. #2
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: reduce _click events

    I would recommend using a control array but since you mentioned UserForm I'm guessing that your're using VBA and it doesn't allow it. However you can loop through the Controls array.
    VB Code:
    1. Dim ctl As Control
    2. '.... other code
    3. For Each ctl In UserForm1.Controls
    4.     If TypeOf ctl Is Label Then
    5.         ctl.BackColor = UserForm1.Label1.BackColor
    6.     End If
    7. Next

  3. #3

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: reduce _click events

    VBA question moved to Office Development.

  5. #5
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: reduce _click events

    Quote Originally Posted by RhinoBull
    That is Controls Collection.
    Yeah yeah...

  6. #6
    Frenzied Member thegreatone's Avatar
    Join Date
    Aug 2003
    Location
    Oslo, Norway. Mhz:4800 x12
    Posts
    1,333

    Re: reduce _click events

    VB Code:
    1. For Each label In Controls
    2. 'do stuff
    3. Next label
    Zeegnahtuer?

Posting Permissions

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



Click Here to Expand Forum to Full Width