Word - How to set Word colors in c#?
Asked By Worduser200 on 17-Jun-08 02:27 PM
How to set Word color in c#? The only colors that I am able to set in Word
are in enumeration WdColor.
Word.WdColor color = Word.WdColor.wdColorTurquoise;
How can I set in c# shadings that are not in enumeration, for example
“Blue, Accent 1�
Thank you.
JeanGuyMarci replied on 17-Jun-08 02:42 PM
In VBA, you can use:
Selection.Range.Font.Color = RGB(10, 60, 165)
Worduser200 replied on 17-Jun-08 03:28 PM
Is there any way to do it in C#?
JeanGuyMarci replied on 17-Jun-08 03:54 PM
I believe RGB is a VB function.
I do not know if there is an equivalent in C#.
This is a VBA group after all...
Try in:
microsoft.public.dotnet.languages.csharp
Tony Jollans replied on 17-Jun-08 06:44 PM
The 2007 Theme Colors are not RGB values. The whole thing is described here:
http://www.wordarticles.com/Articles/Colours/2007.htm (well, maybe not the
whole thing yet, but it should be enough) - it gives VBA code but you can
use the same hex values in any language.
--
Enjoy,
Tony
Cindy M. replied on 18-Jun-08 09:18 AM
I copied the following from the VSTO forum some time ago:
equivalent. The Font.Color property can be set to a WdColor value or the
result of the VB RGB function. The Microsoft.VisualBasic.Information.RGB()
method duplicates this function. So you can do the following:
Code Snippet
rng.Font.Color = (Microsoft.Office.Interop.Word.WdColor)
Microsoft.VisualBasic.Information.RGB(0, 112, 192);
Note that this requires you reference the Microsoft.VisualBasic assembly from
your project.
You can also use the System.Drawing.ColorTranslator.ToOle() method. This
doesn't require the reference to the Microsoft.VisualBasic assembly."
Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org
This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :-)
JeanGuyMarci replied on 18-Jun-08 12:37 PM
Ha! I just noticed the "2007" in the poster alias...
I had just focused on the subject line...
I don't have 2007 on my machine at work and I am not all that good with
C#... Should've stayed away!
Thanks for jumping in!
Amita Chawla replied to Cindy M. on 22-Jan-10 04:24 AM
Hi Cindy,
Thanks for giving this answer! It helped me solve my problem (I was coding in C# and needed an RGB color), and could do it easily using your solution.
cavalm replied to Worduser200 on 06-Aug-12 10:20 AM
d are in enumeration WdColor. Word.WdColor color =3D Word.WdColor.wdColorTu=
rquoise;How can I set in c# shadings that are not in enumeration, for examp=
le =93Blue, Accent 1=94?Thank you.
Here is what I did:
1) Open Word
2) Start record a macro
3) Perform a find and replace from a color in my document to the color that=
I want
4) Stop recording the macro
5) Open the VBA macro=20
6) Find the integer value for the color
7) Replace -738148353 in the example statement below with your value:
selection.Font.Color =3D (Microsoft.Office.Interop.Word.WdColor)(-738148353=
);
Stefan Blom replied to cavalm on 11-Aug-12 02:16 PM
This is an old thread, but you may want to look into the
msoThemeColorSchemeIndex constants?
--
Stefan Blom
Microsoft Word MVP
Here is what I did:
1) Open Word
2) Start record a macro
3) Perform a find and replace from a color in my document to the color that I
want
4) Stop recording the macro
5) Open the VBA macro
6) Find the integer value for the color
7) Replace -738148353 in the example statement below with your value:
selection.Font.Color = (Microsoft.Office.Interop.Word.WdColor)(-738148353);
Stefan Blom replied to Stefan Blom on 11-Aug-12 02:22 PM
... and/or the MsoThemeColorIndex constants.
--
Stefan Blom
Microsoft Word MVP
This is an old thread, but you may want to look into the
msoThemeColorSchemeIndex constants?
--
Stefan Blom
Microsoft Word MVP
Here is what I did:
1) Open Word
2) Start record a macro
3) Perform a find and replace from a color in my document to the color that I
want
4) Stop recording the macro
5) Open the VBA macro
6) Find the integer value for the color
7) Replace -738148353 in the example statement below with your value:
selection.Font.Color = (Microsoft.Office.Interop.Word.WdColor)(-738148353);