By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,556 Members | 1,022 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,556 IT Pros & Developers. It's quick & easy.

How do you set the font color in an EXCEL cell?

P: n/a
Where xlWs is an Excel.Worksheet and xlRG is an Excel.Range
xlRG = xlWS.Cells(row, 7)
xlRG.Font.Bold = True
xlRG.Font.Color = 255

In VB6 you could just simply say xlRG.Font.Color = vbRed but in .net there
is no constant vbRed and Color.Red gives an invalid format. Is there a set of
enumerations of colors that will work here?
Nov 21 '05 #1
Share this Question
Share on Google+
10 Replies

P: n/a
Darrell,

I am in doubt if it is the same colourcode as the Interop wants, however a
colour in VBNet is just easy to get with Color.Red (it is a enum so a bunch
of colours is showed)

I hope this helps?

Cor
"Darrell Wesley" <Da***********@discussions.microsoft.com>
Where xlWs is an Excel.Worksheet and xlRG is an Excel.Range
xlRG = xlWS.Cells(row, 7)
xlRG.Font.Bold = True
xlRG.Font.Color = 255

In VB6 you could just simply say xlRG.Font.Color = vbRed but in .net there
is no constant vbRed and Color.Red gives an invalid format. Is there a set
of
enumerations of colors that will work here?

Nov 21 '05 #2

P: n/a
Hi
xlRG = xlWS.Cells(row, 7)
xlRG.Font.Bold = True
xlRG.Font.Color = 255


Excel-Workbook:
xlWB.Colors(1) = RGB(255,255,255)
xlWB.Colors(2) = RGB(225,225,225)
xlWB.Colors(3) = RGB(200,200,200)

Excel-Worksheet
xlWS.Range("A1:A30").Interior.ColorIndex = 1
xlWS.Range("B1:B30").Interior.ColorIndex = 2
xlWS.Range("C1:C30").Interior.ColorIndex = 3

This works fine for me

Frank

Nov 21 '05 #3

P: n/a
"Darrell Wesley" <Da***********@discussions.microsoft.com> wrote in message news:<33**********************************@microso ft.com>...
Where xlWs is an Excel.Worksheet and xlRG is an Excel.Range
xlRG = xlWS.Cells(row, 7)
xlRG.Font.Bold = True
xlRG.Font.Color = 255

In VB6 you could just simply say xlRG.Font.Color = vbRed but in .net there
is no constant vbRed and Color.Red gives an invalid format. Is there a set of
enumerations of colors that will work here?


Hi Darrell,

What was the exact message? May it is a casting problem.
TTH,
Adel A. Al-saleh
Nov 21 '05 #4

P: n/a
Finally found out how to do this:

xlRG.Font.Color = System.Drawing.Color.ColorTranslator.ToOle(Color.R ed)

and to set the cell background color

xlRG.Interior.Color =
System.Drawing.Color.ColorTranslator.ToOle(Color.L ightBlue)
xlRG.Interior.Pattern = Excel.XlPattern.xlPatternSolid

"Darrell Wesley" wrote:
Where xlWs is an Excel.Worksheet and xlRG is an Excel.Range
xlRG = xlWS.Cells(row, 7)
xlRG.Font.Bold = True
xlRG.Font.Color = 255

In VB6 you could just simply say xlRG.Font.Color = vbRed but in .net there
is no constant vbRed and Color.Red gives an invalid format. Is there a set of
enumerations of colors that will work here?

Nov 21 '05 #5

P: n/a
Darrel,

Thanks for sending this feed back.

However I did not understand why I had not seen it before in the intelisence
of the color and searched for it on MSDN.

And than I saw this.
http://msdn.microsoft.com/library/de...ToOleTopic.asp

And not as a method of color

http://msdn.microsoft.com/library/de...mberstopic.asp

Therefore are you sure that it works as you describe it.

Cor

"Darrell Wesley" <Da***********@discussions.microsoft.com>
Finally found out how to do this:

xlRG.Font.Color = System.Drawing.Color.ColorTranslator.ToOle(Color.R ed)

and to set the cell background color

xlRG.Interior.Color =
System.Drawing.Color.ColorTranslator.ToOle(Color.L ightBlue)
xlRG.Interior.Pattern = Excel.XlPattern.xlPatternSolid

"Darrell Wesley" wrote:
Where xlWs is an Excel.Worksheet and xlRG is an Excel.Range
xlRG = xlWS.Cells(row, 7)
xlRG.Font.Bold = True
xlRG.Font.Color = 255

In VB6 you could just simply say xlRG.Font.Color = vbRed but in .net
there
is no constant vbRed and Color.Red gives an invalid format. Is there a
set of
enumerations of colors that will work here?

Nov 21 '05 #6

P: n/a
YES.

If you try to set the ColorIndex property you will get an error.

Take a look at this

http://msdn.microsoft.com/library/de...l/ExcelObj.asp
"Cor Ligthert" wrote:
Darrel,

Thanks for sending this feed back.

However I did not understand why I had not seen it before in the intelisence
of the color and searched for it on MSDN.

And than I saw this.
http://msdn.microsoft.com/library/de...ToOleTopic.asp

And not as a method of color

http://msdn.microsoft.com/library/de...mberstopic.asp

Therefore are you sure that it works as you describe it.

Cor

"Darrell Wesley" <Da***********@discussions.microsoft.com>
Finally found out how to do this:

xlRG.Font.Color = System.Drawing.Color.ColorTranslator.ToOle(Color.R ed)

and to set the cell background color

xlRG.Interior.Color =
System.Drawing.Color.ColorTranslator.ToOle(Color.L ightBlue)
xlRG.Interior.Pattern = Excel.XlPattern.xlPatternSolid

"Darrell Wesley" wrote:
Where xlWs is an Excel.Worksheet and xlRG is an Excel.Range
xlRG = xlWS.Cells(row, 7)
xlRG.Font.Bold = True
xlRG.Font.Color = 255

In VB6 you could just simply say xlRG.Font.Color = vbRed but in .net
there
is no constant vbRed and Color.Red gives an invalid format. Is there a
set of
enumerations of colors that will work here?


Nov 21 '05 #7

P: n/a
Darell,

Thanks for the page, however there it is not described as you did it.

Colorconverter is a method from system.drawing not from
system.drawing.color.

Cor

"Darrell Wesley" <Da***********@discussions.microsoft.com>
YES.

If you try to set the ColorIndex property you will get an error.

Take a look at this

http://msdn.microsoft.com/library/de...l/ExcelObj.asp
"Cor Ligthert" wrote:
Darrel,

Thanks for sending this feed back.

However I did not understand why I had not seen it before in the
intelisence
of the color and searched for it on MSDN.

And than I saw this.
http://msdn.microsoft.com/library/de...ToOleTopic.asp

And not as a method of color

http://msdn.microsoft.com/library/de...mberstopic.asp

Therefore are you sure that it works as you describe it.

Cor

"Darrell Wesley" <Da***********@discussions.microsoft.com>
> Finally found out how to do this:
>
> xlRG.Font.Color = System.Drawing.Color.ColorTranslator.ToOle(Color.R ed)
>
> and to set the cell background color
>
> xlRG.Interior.Color =
> System.Drawing.Color.ColorTranslator.ToOle(Color.L ightBlue)
> xlRG.Interior.Pattern = Excel.XlPattern.xlPatternSolid
>
> "Darrell Wesley" wrote:
>
>> Where xlWs is an Excel.Worksheet and xlRG is an Excel.Range
>>
>>
>> xlRG = xlWS.Cells(row, 7)
>> xlRG.Font.Bold = True
>> xlRG.Font.Color = 255
>>
>> In VB6 you could just simply say xlRG.Font.Color = vbRed but in .net
>> there
>> is no constant vbRed and Color.Red gives an invalid format. Is there a
>> set of
>> enumerations of colors that will work here?


Nov 21 '05 #8

P: n/a
Darell,

Thanks for the page, however there it is not described as you did it.

Colorconverter is a method from system.drawing not from
system.drawing.color.

Cor

"Darrell Wesley" <Da***********@discussions.microsoft.com>
YES.

If you try to set the ColorIndex property you will get an error.

Take a look at this

http://msdn.microsoft.com/library/de...l/ExcelObj.asp
"Cor Ligthert" wrote:
Darrel,

Thanks for sending this feed back.

However I did not understand why I had not seen it before in the
intelisence
of the color and searched for it on MSDN.

And than I saw this.
http://msdn.microsoft.com/library/de...ToOleTopic.asp

And not as a method of color

http://msdn.microsoft.com/library/de...mberstopic.asp

Therefore are you sure that it works as you describe it.

Cor

"Darrell Wesley" <Da***********@discussions.microsoft.com>
> Finally found out how to do this:
>
> xlRG.Font.Color = System.Drawing.Color.ColorTranslator.ToOle(Color.R ed)
>
> and to set the cell background color
>
> xlRG.Interior.Color =
> System.Drawing.Color.ColorTranslator.ToOle(Color.L ightBlue)
> xlRG.Interior.Pattern = Excel.XlPattern.xlPatternSolid
>
> "Darrell Wesley" wrote:
>
>> Where xlWs is an Excel.Worksheet and xlRG is an Excel.Range
>>
>>
>> xlRG = xlWS.Cells(row, 7)
>> xlRG.Font.Bold = True
>> xlRG.Font.Color = 255
>>
>> In VB6 you could just simply say xlRG.Font.Color = vbRed but in .net
>> there
>> is no constant vbRed and Color.Red gives an invalid format. Is there a
>> set of
>> enumerations of colors that will work here?


Nov 21 '05 #9

P: n/a
You are so right. Thanks.

"Cor Ligthert" wrote:
Darell,

Thanks for the page, however there it is not described as you did it.

Colorconverter is a method from system.drawing not from
system.drawing.color.

Cor

"Darrell Wesley" <Da***********@discussions.microsoft.com>
YES.

If you try to set the ColorIndex property you will get an error.

Take a look at this

http://msdn.microsoft.com/library/de...l/ExcelObj.asp
"Cor Ligthert" wrote:
Darrel,

Thanks for sending this feed back.

However I did not understand why I had not seen it before in the
intelisence
of the color and searched for it on MSDN.

And than I saw this.
http://msdn.microsoft.com/library/de...ToOleTopic.asp

And not as a method of color

http://msdn.microsoft.com/library/de...mberstopic.asp

Therefore are you sure that it works as you describe it.

Cor

"Darrell Wesley" <Da***********@discussions.microsoft.com>
> Finally found out how to do this:
>
> xlRG.Font.Color = System.Drawing.Color.ColorTranslator.ToOle(Color.R ed)
>
> and to set the cell background color
>
> xlRG.Interior.Color =
> System.Drawing.Color.ColorTranslator.ToOle(Color.L ightBlue)
> xlRG.Interior.Pattern = Excel.XlPattern.xlPatternSolid
>
> "Darrell Wesley" wrote:
>
>> Where xlWs is an Excel.Worksheet and xlRG is an Excel.Range
>>
>>
>> xlRG = xlWS.Cells(row, 7)
>> xlRG.Font.Bold = True
>> xlRG.Font.Color = 255
>>
>> In VB6 you could just simply say xlRG.Font.Color = vbRed but in .net
>> there
>> is no constant vbRed and Color.Red gives an invalid format. Is there a
>> set of
>> enumerations of colors that will work here?


Nov 21 '05 #10

P: n/a
You are so right. Thanks.

"Cor Ligthert" wrote:
Darell,

Thanks for the page, however there it is not described as you did it.

Colorconverter is a method from system.drawing not from
system.drawing.color.

Cor

"Darrell Wesley" <Da***********@discussions.microsoft.com>
YES.

If you try to set the ColorIndex property you will get an error.

Take a look at this

http://msdn.microsoft.com/library/de...l/ExcelObj.asp
"Cor Ligthert" wrote:
Darrel,

Thanks for sending this feed back.

However I did not understand why I had not seen it before in the
intelisence
of the color and searched for it on MSDN.

And than I saw this.
http://msdn.microsoft.com/library/de...ToOleTopic.asp

And not as a method of color

http://msdn.microsoft.com/library/de...mberstopic.asp

Therefore are you sure that it works as you describe it.

Cor

"Darrell Wesley" <Da***********@discussions.microsoft.com>
> Finally found out how to do this:
>
> xlRG.Font.Color = System.Drawing.Color.ColorTranslator.ToOle(Color.R ed)
>
> and to set the cell background color
>
> xlRG.Interior.Color =
> System.Drawing.Color.ColorTranslator.ToOle(Color.L ightBlue)
> xlRG.Interior.Pattern = Excel.XlPattern.xlPatternSolid
>
> "Darrell Wesley" wrote:
>
>> Where xlWs is an Excel.Worksheet and xlRG is an Excel.Range
>>
>>
>> xlRG = xlWS.Cells(row, 7)
>> xlRG.Font.Bold = True
>> xlRG.Font.Color = 255
>>
>> In VB6 you could just simply say xlRG.Font.Color = vbRed but in .net
>> there
>> is no constant vbRed and Color.Red gives an invalid format. Is there a
>> set of
>> enumerations of colors that will work here?


Nov 21 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.