Word 2013及新版中ActiveDocument.Paragraphs(1).Range.Font.color不可用,如何用RGB设色?
Hey there, let's tackle your two Word VBA questions step by step:
Actually, this property is fully available in Word 2013. The confusion usually comes from a few edge cases:
- If you're migrating code from an extremely old Word version (like Word 97), there might be compatibility warnings, but the property itself works as intended.
- If you haven't properly referenced the Word Object Library in your VBA project (check via Tools > References in the VBA editor), you might get a compile error that makes it seem like the property doesn't exist.
In most normal development scenarios, you can use this property without issues in Word 2013.
ColorIndex in newer Word versions? If you're running into situations where the Font.Color property isn't behaving as expected (rare in modern Word, but possible in some restricted environments), here are reliable ways to set custom RGB colors without relying on the limited preset options of ColorIndex:
Method 1: Directly assign RGB values to Font.Color
This is the standard approach and works in almost all cases:
' Set the first paragraph's font to bright red ActiveDocument.Paragraphs(1).Range.Font.Color = RGB(255, 0, 0)
The RGB() function takes three integers (0-255) for red, green, and blue channels, letting you define any custom color you need.
Method 2: Use Font.TextColor.RGB as an alternative
If Font.Color throws an error (e.g., in some COM interop scenarios), try targeting the text color object directly:
' Set the first paragraph's font to forest green ActiveDocument.Paragraphs(1).Range.Font.TextColor.RGB = RGB(34, 139, 34)
This syntax is fully supported in Word 2016 and later versions.
Method 3: Use wdColorRGB helper (optional)
For extra clarity, you can wrap your RGB values in the wdColorRGB function:
' Set the first paragraph's font to deep blue ActiveDocument.Paragraphs(1).Range.Font.Color = wdColorRGB(0, 0, 139)
All these methods let you escape the constraints of ColorIndex and create exact, custom color shades for your text.
内容的提问来源于stack exchange,提问作者chan

