EdwardMartinIII
Technical User
I have a Word 2007 doc with a lot of status buttons on it. Hundreds, in fact.
For each button, this is the code I plan to have:
The same action happens for each button.
Obviously, this is a lot of copy-and-pasting, and I'd have to change a line in each procedure.
Is there a simpler way to do this?
For example, is there a way for each procedure to have a line that reads:
Another example:
Is it possible to build a single procedure, such as this:
and having that procedure called by each button click like this:
I'm open to suggestions.
I'm not against coding each button individually, but if there was a slicker way, I'd really like to do that instead.
Thanks!
Edward
"Cut a hole in the door. Hang a flap. Criminy, why didn't I think of this earlier?!" -- inventor of the cat door
For each button, this is the code I plan to have:
Code:
Private Sub CommandButton1_Click()
With CommandButton1
Select Case .BackColor
Case Is = &HFF&
' Button is red and should be switched to orange.
.BackColor = &H80FF&
' Text should be changed from "High" to "Medium"
.Caption = "Medium"
Case Is = &H80FF&
' Button is orange and should be switched to yellow.
.BackColor = &HFFFF&
' Text should be changed from "Medium" to "Low"
.Caption = "Low"
Case Is = &HFFFF&
' Button is yellow and should be switched to green.
.BackColor = &HFF00&
' Text should be changed from "Low" to "None"
.Caption = "None"
Case Is = &HFF00&
' Button is green and should be switched to gray.
.BackColor = &HC0C0C0
' Text should be changed from "None" to "N/A"
.Caption = "N/A"
Case Is = &HC0C0C0
' Button is gray and should be switched to red.
.BackColor = &HFF&
' Text should be changed from "None" to "High"
.Caption = "High"
End Select
End With
End Sub
The same action happens for each button.
Obviously, this is a lot of copy-and-pasting, and I'd have to change a line in each procedure.
Is there a simpler way to do this?
For example, is there a way for each procedure to have a line that reads:
Code:
Private Sub CommandButton1_Click()
With TheControlClickedToCallThis [b]<--is there something like this?[/b]
Select Case .BackColor
Case Is = &HFF&
' Button is red and should be switched to orange.
.BackColor = &H80FF&
' Text should be changed from "High" to "Medium"
...(and so forth)
Another example:
Is it possible to build a single procedure, such as this:
Code:
Private Toggle_The Switch()
With TheControlClickedToCallThis
Select Case .BackColor
Case Is = &HFF&
' Button is red and should be switched to orange.
.BackColor = &H80FF&
' Text should be changed from "High" to "Medium"
.Caption = "Medium"
Case Is = &H80FF&
' Button is orange and should be switched to yellow.
.BackColor = &HFFFF&
' Text should be changed from "Medium" to "Low"
.Caption = "Low"
Case Is = &HFFFF&
' Button is yellow and should be switched to green.
.BackColor = &HFF00&
' Text should be changed from "Low" to "None"
.Caption = "None"
Case Is = &HFF00&
' Button is green and should be switched to gray.
.BackColor = &HC0C0C0
' Text should be changed from "None" to "N/A"
.Caption = "N/A"
Case Is = &HC0C0C0
' Button is gray and should be switched to red.
.BackColor = &HFF&
' Text should be changed from "None" to "High"
.Caption = "High"
End Select
End With
End Sub
and having that procedure called by each button click like this:
Code:
Private Sub CommandButton1_Click()
Toggle_The Switch
End Sub
I'm open to suggestions.
I'm not against coding each button individually, but if there was a slicker way, I'd really like to do that instead.
Thanks!
Edward
"Cut a hole in the door. Hang a flap. Criminy, why didn't I think of this earlier?!" -- inventor of the cat door