So I'm working on creating a document for some folks where each group, of which there are three, is assigned a font color for their input into the document. I've written a VBA script that contains a list of everyone involved and can identify the person logged into the computer and the group they are with. However, I am unable to get the font color to set itself. I recorded a VBA script where I set the font color to see how Word does it, but the resulting code of Selection.Font.Color = wdColorRed
won't actually change the selected font color when I add it to my VBA script. Here is an example of the code that I'm using:
Private Sub Document_Open()
Dim Users As New Scripting.Dictionary
Dim UserID As String
Dim category As String
UserID = GetUserName 'Currently using the example at
'http://support.microsoft.com/kb/161394 as a function
'---Add Members of Group 1---
Users.Add "person1", "group1"
Users.Add "person2", "group1"
'---Add Members of Group 2---
Users.Add "person3", "group2"
Users.Add "person4", "group2"
Users.Add "person5", "group2"
'---Add Members of Group 3---
Users.Add "person6", "group3"
Users.Add "person7", "group3"
For Each user In Users.Keys
If user = UserID Then
If Users.Item(user) = "group1" Then
Selection.Font.Color = wdColorRed
ElseIf Users.Item(user) = "group2" Then
Selection.Font.Color = wdColorGreen
ElseIf Users.Item(user) = "group3" Then
Selection.Font.Color = wdColorBlue
Else
Selection.Font.Color = wdColorBlack
End If
End If
Next
End Sub
AFAIK, You can't set a default font color for a specific user. Even if you managed to, say, set it to Blue and you navigate to a sentence which is in red color and if you typed anything, you will not see blue text but red text. Because the position where the cursor is will pick the original color that was used to color that sentence.
To set a specific color for a user, you will either have to either
Identify a range and set the color for it
. But then like I mentioned above, if the user navigates to a different range then the new color setting will not apply there.
Set it for the entire document
. If you set it for the entire document then the color of the entire document will change and I am sure this is not what you want.