Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-19-2025, 05:52 PM
Astrid Astrid is offline In a style set font color to themecolor Windows 10 In a style set font color to themecolor Office 2019
Novice
In a style set font color to themecolor
 
Join Date: Apr 2022
Posts: 9
Astrid is on a distinguished road
Default In a style set font color to themecolor

I like to set the color of a font in a paragraph style to an accentcolor (from the document theme).



On a range I can use:
Selection.Font.Fill.ForeColor.ObjectThemeColor =wdThemeColorAccent2

however if I try to apply the color to a font in a style, I get an error 4680 (That property is not supported for this object)
ActiveDocument.Styles(wdStyleHeading1).Font.Fill.F oreColor.ObjectThemeColor = wdThemeColorAccent2

I can set the color if I use
ActiveDocument.Styles(wdStyleHeading1).Font.Color = ActiveDocument.DocumentTheme.ThemeColorScheme(msoT hemeAccent2)
however it doesn't point to the position in the theme but uses it's RGB. That's not what I want.
(Note that the .Color property of a font still works)

Does anybody know how to archieve this?
I was also wondering why I need the msoThemeAccent enum instead of the wdThemeColorAccent. I was under the impression that for Word objects I need the wdThemeColorAccent and for Office objects the msoThemeColor?
Reply With Quote
  #2  
Old 03-20-2025, 12:26 AM
Guessed's Avatar
Guessed Guessed is offline In a style set font color to themecolor Windows 10 In a style set font color to themecolor Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,166
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

Try this instead
Code:
ActiveDocument.Styles(wdStyleHeading1).Font.Color = -721354753
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #3  
Old 03-20-2025, 01:36 AM
Astrid Astrid is offline In a style set font color to themecolor Windows 10 In a style set font color to themecolor Office 2019
Novice
In a style set font color to themecolor
 
Join Date: Apr 2022
Posts: 9
Astrid is on a distinguished road
Default

Thanks for your response.

This changes only the color. This is not what I want to archieve.
I want to set the color to the relative position in the palet, not to a fixed value, so that when the theme is changed, the color in the style changes as well.
Reply With Quote
  #4  
Old 03-20-2025, 01:42 AM
Guessed's Avatar
Guessed Guessed is offline In a style set font color to themecolor Windows 10 In a style set font color to themecolor Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,166
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

That number is for Accent2, not a fixed rgb value. Give it a try and I believe it will work on your machine the same as it does on mine
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #5  
Old 03-20-2025, 01:49 AM
Astrid Astrid is offline In a style set font color to themecolor Windows 10 In a style set font color to themecolor Office 2019
Novice
In a style set font color to themecolor
 
Join Date: Apr 2022
Posts: 9
Astrid is on a distinguished road
Default

Thank you so much!
You're right. That seems to do the trick.

Can you tell me what this number is? Is it a value for a constant? Any place I can find the other numbers for the various accent colors?
Reply With Quote
  #6  
Old 03-20-2025, 02:17 AM
Italophile Italophile is offline In a style set font color to themecolor Windows 11 In a style set font color to themecolor Office 2021
Expert
 
Join Date: Mar 2022
Posts: 542
Italophile is just really niceItalophile is just really niceItalophile is just really niceItalophile is just really nice
Default

The Word object model does not support setting the font color of a style to a theme color. The code below will generate an error if you try it.

Code:
ActiveDocument.Styles(wdStyleHeading1).Font.Fill.ForeColor.ObjectThemeColor = wdThemeColorAccent2
The negative RGB value isn't a constant but can be determined using the following code, where a theme color has already been applied to the style

Code:
Debug.Print ActiveDocument.Styles(wdStyleHeading1).Font.Color
If you work through each of the colors you can create your own constants. Watch out for tints and shades though!

If you're feeling brave, there is an article that explains theme colors in depth: Word Articles: Colours in 2007
Reply With Quote
  #7  
Old 03-20-2025, 02:23 AM
Astrid Astrid is offline In a style set font color to themecolor Windows 10 In a style set font color to themecolor Office 2019
Novice
In a style set font color to themecolor
 
Join Date: Apr 2022
Posts: 9
Astrid is on a distinguished road
Default

Thank you!!!
This is very helpful and will save me a lot of problems.

Have a very nice day and thank you both for helping me out.
Reply With Quote
Reply

Tags
color, style, theme



Similar Threads
Thread Thread Starter Forum Replies Last Post
Style Font Color Changes After Close?? the.ronin Word 2 05-20-2018 07:26 PM
Style Font Color: Background 1 gmgj Word 3 12-20-2017 04:00 PM
In a style set font color to themecolor Hyperlink style won't accept font color or underlining Jennifer Murphy Word 14 03-19-2017 03:02 PM
Font Color Question//.Replacement.Font.Color = 12611584 rsrasc Word VBA 3 09-05-2015 09:03 PM
Setting Font Color and Style "permanently" wings1080 Word 5 12-19-2014 08:44 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:47 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft