 | [Excel] Changing button colour on a UserFormI have a simple userform with toggle buttons on it. Because they are so insipid as default colours, I want to change the ForeColor when the form loads, based on the value of the ControlSource for each button, True to Red and False to Blue.
What I have so far is;
Private Sub CommandButton1_Click()
UserForm1.Show
For Each Control In UserForm.Controls
If Control.Name Like "ToggleButton?" Then
If Control.ControlSource.Value = "TRUE" Then Control.ForeColor = RGB(255, 0, 0) Else Control.FOreColor = RGB(0,0,255)
End If
Next
End Sub
Why isn't it working? |
|
 CudniLa Merma - VigiladoPremium,MVM join:2003-12-20 Someshire kudos:13 | As a guess, maybe the control.name value needs to be correct
Cudni |
|
 | Yes, I noticed that my typed code had that error...it still didn't fix it but I've moved on to doing it a different way now and I'm banging my head against another problem.
My form has a multipage on a multipage. I have about 20 toggle boxes on this nested multipage, and I have a control button that I want to click to set them all to "true".
I know if they were on a single multipage I'd use;
Private Sub CommandButton2_Click()
Dim TB As Control
For Each TB In Me.MultiPage1.Pages(1).Controls
If Left(TB.Name, 6) = "Toggle" Then TB.Value = True
Next TB
End Sub
...but I cannot find for the life of me how to only toggle the buttons on my nested multipage. Multipage1.Pages(1).Multipage...etc isn't working... |
|
 CudniLa Merma - VigiladoPremium,MVM join:2003-12-20 Someshire kudos:13 | reply to Grey Area Repeat code for singe page for all pages? So as you referred to multipage1 do it again for multipage2 etc
Cudni |
|
 | It's okay, I think I've figured it out. Nesting the multipages doesn't make any difference...so my multipage that is itself on a multipage is simply multipage 2...it's no more complicated than that!
Now I just have to figure why my code to select all my toggle buttons...isn't...I have 20 on this page...it toggles the first one, skips numbers 2 to 6 and toggles the rest. If I click the command button a second time, it toggles the five it missed the first time.
Grrrr. |
|
 | I still need some help with this. I can set a command button on my userform's multipage to run the following;
Private Sub CommandButton1_Click()
Dim pPage As Page, TB As Control
For Each TB In UserForm1.MultiPage2.Pages(1).Controls
If TB.Value = "True" Then TB.ForeColor = RGB(0, 255, 0) Else TB.Forecolor = RGB(255,0,0)
Next TB
End Sub
All the togglebuttons have their own ControlSource property set to an individual cell on the field, so that the status of the buttons is remembered. What I want is for the form to appear with the colour changes already reflected depending on the cell value instead of me having to click the button to do it. Is there a "UserFormOpen" command or similar? Any other ideas? |
|
 | With the code above, running from the button, It still seems to skip some of the Controlsource fields...the buttons show toggled but the controlsource isn't updated.
I tried "Step Into" and going through by pressing F8 and it works fine, so is it a timing issue? It's almost as if the code is running to fast for Excel to keep up. |
|
|
|