I am not sure what, if any color is represented by &H8000000F
However, the following works:
If ActiveDocument.Variables("Personal").Value = "test" Then
CommandButton1.BackColor = wdColorRed
Else
CommandButton1.BackColor = wdColorGreen
End If
--
Hope this helps.
Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.
Doug Robbins - Word MVP
Patrick C. Simonds said:
Can anyone explain to me why the code below does not change the BackColor
of CommandButton1?
I added the "MsgBox ActiveDocument.Variables("Personal").Value" code
just so I could make sure the variable value was in fact "test".
Private Sub UserForm_Initialize()
MsgBox ActiveDocument.Variables("Personal").Value
If ActiveDocument.Variables("Personal").Value = "test" Then
CommandButton1.BackColor = &H8000000F
End If
End Sub
Doug Robbins - Word MVP said:
You do not have to specifically "Add" a document variable. Assigning a
value to it with
[document object].Variables("Varname").Value =
will cause it to be created with the assigned value if it does not
exist, or change the value assigned to it if it already exists.
--
Hope this helps.
Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.
Doug Robbins - Word MVP
This did the trick. If anyone has a better way though I am always ready
to learn.
Private Sub CommandButton1_Click()
Unload UserForm1
On Error GoTo Continue
ActiveDocument.Variables.Add Name:="Incomplete"
Continue:
Title = (Me.OptionButton1 Or Me.OptionButton2 Or Me.OptionButton3 Or
Me.OptionButton4)
If Title = False Then
ActiveDocument.Variables("Incomplete").Value = True
End If
End Sub
My problem now is that having created the code below, if I access the
UserForm again I get an error because the variable all ready exists.
Private Sub CommandButton1_Click()
Unload UserForm1
Title = (Me.OptionButton1 Or Me.OptionButton2 Or Me.OptionButton3 Or
Me.OptionButton4)
If Title = False Then
ActiveDocument.Variables.Add Name:="Incomplete", Value:="True"
End If
End Sub
I think I may have figured this out. I will be back if things do not
work out. Thanks
This is what I need to do:
If TextBox1 on UserForm1 is blank when the UserForm is unloaded, I
want to create a public variable called "incomplete" (would also
want that variable deleted if it already existed and TextBox1 were
not blank when the UserForm where unloaded). Then when I open
UserForm4 if the variable "incomplete" exists, I want the BackColor
of CommandButton1 to be red.