How to set Word colors in c#?

W

Word user 2007

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.
 
J

Jean-Guy Marcil

Word user 2007 said:
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�

In VBA, you can use:

Selection.Range.Font.Color = RGB(10, 60, 165)
 
J

Jean-Guy Marcil

Word user 2007 said:
Is there any way to do it in C#?

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
 
C

Cindy M.

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�
I copied the following from the VSTO forum some time ago:

"You can't directly convert a System.Drawing.Color value to its WdColor
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 :)
 
J

Jean-Guy Marcil

Tony Jollans said:
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.

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!
 
A

Amita Chawla

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.



Cindy M. wrote:

Re: How to set Word colors in c#?
18-Jun-08

I copied the following from the VSTO forum some time ago

"You can't directly convert a System.Drawing.Color value to?its WdColor
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 Snippe
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 Meiste
INTER-Solutions, Switzerlan
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005
http://www.word.mvps.or

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)

Previous Posts In This Thread:

How to set Word colors in c#?
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.

RE: How to set Word colors in c#?

In VBA, you can use

Selection.Range.Font.Color = RGB(10, 60, 165)

RE: How to set Word colors in c#?


Is there any way to do it in C#?

RE: How to set Word colors in c#?

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

The 2007 Theme Colors are not RGB values.
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
Ton


Re: How to set Word colors in c#?
I copied the following from the VSTO forum some time ago

"You can't directly convert a System.Drawing.Color value to?its WdColor
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 Snippe
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 Meiste
INTER-Solutions, Switzerlan
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005
http://www.word.mvps.or

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)

Re: How to set Word colors in c#?

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!


Submitted via EggHeadCafe - Software Developer Portal of Choice
ASP.NET Multi-Lingual Language Translations
http://www.eggheadcafe.com/tutorial...d56-766a992561ef/aspnet-multilingual-lan.aspx
 
C

cavalmi

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.

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 thatI 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);
 
S

Stefan Blom

This is an old thread, but you may want to look into the
msoThemeColorSchemeIndex constants?

--
Stefan Blom
Microsoft Word MVP




wrote in message
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.

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);
 
S

Stefan Blom

.... and/or the MsoThemeColorIndex constants.

--
Stefan Blom
Microsoft Word MVP




"Stefan Blom" wrote in message
This is an old thread, but you may want to look into the
msoThemeColorSchemeIndex constants?

--
Stefan Blom
Microsoft Word MVP




wrote in message
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.

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);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top