If you have any problems with this web page, please first read my browser notesbrowser notes [link to ../../Miscellany/Browsers/Browsers.php] and if you still have issues, feel free to e-mail mee-mail me [link to e-mail the author at mailto:Tony@WordArticles.com]

Interpreting colour properties

Interpreting

Interpreting Theme Colour Codes

Ultimately you will probably want to do something else with the data returned by the Colours2 procedure presented in the main article – apply a darker shade of the background colour to the border, perhaps, or apply some complementary colour with the same tint to another element. Whatever it may be, a simpler process, which, if nothing else, can give you the confidence that what you have so far is correct, is to translate the codes into natural language. The code presented here, mainly as a diversion, does just that. There is no easy way to do it, no shortcut provided by the system. Word knows, but will not tell you, the names of all the colours and there is nothing for it but to code your own translation routine.

There are two codes to translate. The first is the theme colour index, and a function to translate it must take it as input, and then return the translation as an output text string. Just for fun, here's a routine that optionally takes an extra argument of the language to return the result in, and defaults to the User Interface language if one is not supplied. It also defaults to English if there is no text available in the language requested; if you want to use a language other than the French, Dutch, or English shown here (perhaps you don’t live in Belgium), you are left to add it yourself.

There are other, probably better, ways to code this, but this way, I hope, makes it clear what is going on and it is fine for demonstration purposes.

Function ThemeColorName(ThemeColorIndex As WdThemeColorIndex, _
                        Optional LanguageId As MsoLanguageID) _
         As String

    If LanguageId = 0 Then
        LanguageId = LanguageSettings.LanguageId(msoLanguageIDUI)
    End If
    
    Select Case LanguageId
    
        Case msoLanguageIDDutch
            
            Select Case ThemeColorIndex
                Case wdThemeColorMainDark1:         ThemeColorName = "Donker 1"
                Case wdThemeColorMainLight1:        ThemeColorName = "Licht 1"
                Case wdThemeColorMainDark2:         ThemeColorName = "Donker 2"
                Case wdThemeColorMainLight2:        ThemeColorName = "Licht 2"
                Case wdThemeColorAccent1:           ThemeColorName = "Accent 1"
                Case wdThemeColorAccent2:           ThemeColorName = "Accent 2"
                Case wdThemeColorAccent3:           ThemeColorName = "Accent 3"
                Case wdThemeColorAccent4:           ThemeColorName = "Accent 4"
                Case wdThemeColorAccent5:           ThemeColorName = "Accent 5"
                Case wdThemeColorAccent6:           ThemeColorName = "Accent 6"
                Case wdThemeColorHyperlink:         ThemeColorName = "Hyperlink"
                Case wdThemeColorHyperlinkFollowed: ThemeColorName = "Gevolgde Hyperlink"
                Case wdThemeColorBackground1:       ThemeColorName = "Achtergrond 1"
                Case wdThemeColorText1:             ThemeColorName = "Tekst 1"
                Case wdThemeColorBackground2:       ThemeColorName = "Achtergrond 2"
                Case wdThemeColorText2:             ThemeColorName = "Tekst 2"
                Case Else:                          ThemeColorName = "Onbekent " & ThemeColorIndex
            End Select
        
        Case msoLanguageIDFrench
            
            Select Case ThemeColorIndex
                Case wdThemeColorMainDark1:         ThemeColorName = "Sombre 1"
                Case wdThemeColorMainLight1:        ThemeColorName = "Clair 1"
                Case wdThemeColorMainDark2:         ThemeColorName = "Sombre 2"
                Case wdThemeColorMainLight2:        ThemeColorName = "Clair 2"
                Case wdThemeColorAccent1:           ThemeColorName = "Accentuation 1"
                Case wdThemeColorAccent2:           ThemeColorName = "Accentuation 2"
                Case wdThemeColorAccent3:           ThemeColorName = "Accentuation 3"
                Case wdThemeColorAccent4:           ThemeColorName = "Accentuation 4"
                Case wdThemeColorAccent5:           ThemeColorName = "Accentuation 5"
                Case wdThemeColorAccent6:           ThemeColorName = "Accentuation 6"
                Case wdThemeColorHyperlink:         ThemeColorName = "Lien hypertexte"
                Case wdThemeColorHyperlinkFollowed: ThemeColorName = "Lien hypertexte visit"
                Case wdThemeColorBackground1:       ThemeColorName = "Arrire-plan 1"
                Case wdThemeColorText1:             ThemeColorName = "Texte 1"
                Case wdThemeColorBackground2:       ThemeColorName = "Arrire-plan 2"
                Case wdThemeColorText2:             ThemeColorName = "Texte 2"
                Case Else:                          ThemeColorName = "Inconnu " & ThemeColorIndex
            End Select
        
        Case Else ' msoLanguageIDEnglishUS
            
            Select Case ThemeColorIndex
                Case wdThemeColorMainDark1:         ThemeColorName = "Dark 1"
                Case wdThemeColorMainLight1:        ThemeColorName = "Light 1"
                Case wdThemeColorMainDark2:         ThemeColorName = "Dark 2"
                Case wdThemeColorMainLight2:        ThemeColorName = "Light 2"
                Case wdThemeColorAccent1:           ThemeColorName = "Accent 1"
                Case wdThemeColorAccent2:           ThemeColorName = "Accent 2"
                Case wdThemeColorAccent3:           ThemeColorName = "Accent 3"
                Case wdThemeColorAccent4:           ThemeColorName = "Accent 4"
                Case wdThemeColorAccent5:           ThemeColorName = "Accent 5"
                Case wdThemeColorAccent6:           ThemeColorName = "Accent 6"
                Case wdThemeColorHyperlink:         ThemeColorName = "Hyperlink"
                Case wdThemeColorHyperlinkFollowed: ThemeColorName = "Followed Hyperlink"
                Case wdThemeColorBackground1:       ThemeColorName = "Background 1"
                Case wdThemeColorText1:             ThemeColorName = "Text 1"
                Case wdThemeColorBackground2:       ThemeColorName = "Background 2"
                Case wdThemeColorText2:             ThemeColorName = "Text 2"
                Case Else:                          ThemeColorName = "Unknown " & ThemeColorIndex
            End Select
    
    End Select

End Function

The second code to translate is the tint and shade code. The code is relatively straightforward and is presented without explanation. If you're displaying the Theme colour in a language, it makes sense to also display the darkness or lightness texts in the same language; to this end it makes sense to isolate the code in its own Function. Just as the earlier routine took the Theme colour index and an optional language identifier, this one will take the TintAnd Shade value and an optional language identifier. The string it returns, if not empty, will begin with a comma as it is intended to be appended to the end of the message.

Function TintAndShadeText(TintAndShade As Double, _
                          Optional LanguageId As MsoLanguageID) _
         As String

    If LanguageId = 0 Then
        LanguageId = LanguageSettings.LanguageId(msoLanguageIDUI)
    End If
    
    Select Case TintAndShade
    
        Case 0

            TintAndShadeText = ""
            
        Case Is > 0
            
            Select Case LanguageId
                Case msoLanguageIDDutch
                    TintAndShadeText = ", lichter "
                Case msoLanguageIDFrench
                    TintAndShadeText = ", plus clair "
                Case Else
                    TintAndShadeText = ", lighter "
            End Select
        
            TintAndShadeText = TintAndShadeText & TintAndShade * 100 & "%"
        
        Case Is < 0
            
            Select Case LanguageId
                Case msoLanguageIDDutch
                    TintAndShadeText = ", donkerder "
                Case msoLanguageIDFrench
                    TintAndShadeText = ", plus sombre "
                Case Else
                    TintAndShadeText = ", darker "
            End Select
    
            TintAndShadeText = TintAndShadeText & TintAndShade * -100 & "%"
        
    End Select

End Function

Now that you have these two translation routines, all that remains to do is to invoke them from the Colours2 routine. This doesn’t work standalone, it still needs the various subroutines you have already seen, but the change to incorporate the translation is simplicity itself.

Sub Colours2()

    With QueryColour(Selection.Cells(1).Shading.BackgroundPatternColor)

        Select Case .ColourType
            Case ColourTypeRGB
                MsgBox "The background of the cell is a standard RGB value"
            Case ColourTypeAutomatic
                MsgBox "The background of the cell is set to Automatic"
            Case ColourTypeSystem
                MsgBox "The background of the cell is set to a Windows system colour"

            Case ColourTypeThemeLow
                MsgBox "The background of the cell is set to Theme colour: " & _
                       ThemeColorName(.ThemeColorIndex) & _
                       TintAndShadeText(.TintAndShade)

            Case Else
                MsgBox "The background of the cell is not in a recognised format"

        End Select

    End With
    
End Sub

I’m sure you are capable of putting the code here together with the code already in the main article, and if you do you will see a message something like this:

An example message box
An example translation in a message box

After that relaxing interlude it’s time to return to the frayreturn to the fray [link to Querying, in the main article at 2007.php#QueryingColoursII] and discover how to turn the codes into red, green, and blue colour values.