0

Is there a way to make it so when a VBA MS Word Userform toggle button is clicked only part of the caption text changes colors?
E.g. "Upper (case) / Lower (case)." Upper turns from black to green when clicked, before reverting to black after a few seconds. And the same with Lower the next time the button is clicked.

I have no clue how to do this.
The code so far that changes the entire caption that I have is:

Private Sub CommandButton199_Click()
CommandButton199.BackColor = 8388608
Selection.range.Case = wdToggleCase
Application.OnTime when:=Now + TimeValue("00:00:04"), _
Name:="Module2.macro2"
End Sub

Sub MACRO2()
Dim myArray As Variant
myArray = Array(199) ' [I'm going to be adding another dozen buttons]
For x = LBound(myArray) To UBound(myArray)
Normal.Fonts.Controls("CommandButton" & Val(myArray(x))).BackColor = 8421376
Next x
End Sub
greybeard
  • 2,249
  • 8
  • 30
  • 66
Ken
  • 1
  • 1
    No, the caption is a single string. You'd need to split the text across an additional label to achieve what you want, and then you'll have alignment issues. – Timothy Rylatt Jun 06 '23 at 07:48
  • 1
    You could however change the caption text, since you can keep track of what's active (Upper or Lower) – Notus_Panda Jun 07 '23 at 15:48
  • As the two gentlemen upstairs have said. But your code has at least two problems: 1, `Array(199)` , the argument must be an arglist that is [*a comma-delimited list of values*](https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/array-function) 2. `Normal.Fonts.Controls` Is there such an object? – Oscar Sun Jun 07 '23 at 16:32

0 Answers0