473,405 Members | 2,334 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

TAB COLOR

Hi I hope people are still talking in this group because I can't seem
to find any help on this. I am using Excel Interop and programming in
C#. I have Excel all setup and adding worksheets and everything, but
now I have a request from my users to change the tab color. Of course
they can do this manually and I was able to do it with the macro

CurrSht.Tab.ColorIndex = 4

but that doesn't work in C#. I keep getting an error about setting an
int to ColorIndex. I tried using CurrSht.Tab.Color = 4 and that does
change the tab color, but to black. No matter what number I use the
color is black.

Please anyone with some input I would appreciate it, I have been going
crazy for the last 9 hours because of a simple thing as tab color.

Thanks

Aug 10 '06 #1
6 9290
The Color property expects a RGB value. I couldn't find any docs exactly
what the RGB function in Excel returns but I suspect it's the same as in
GDI, i.e. an int in the form 0x00bbggrr. Setting this to the value 4 is
actually slightly red, but it will look pretty much black since the red
value is so low.

The ColorIndex property should work though. It's a just an index in a color
palette so if you can set it to 4 from inside Excel you should be able to do
the same thing from your app. What error do you get?

/claes

"ILProgrammer" <sw**********@sweettrouble.comwrote in message
news:11**********************@75g2000cwc.googlegro ups.com...
Hi I hope people are still talking in this group because I can't seem
to find any help on this. I am using Excel Interop and programming in
C#. I have Excel all setup and adding worksheets and everything, but
now I have a request from my users to change the tab color. Of course
they can do this manually and I was able to do it with the macro

CurrSht.Tab.ColorIndex = 4

but that doesn't work in C#. I keep getting an error about setting an
int to ColorIndex. I tried using CurrSht.Tab.Color = 4 and that does
change the tab color, but to black. No matter what number I use the
color is black.

Please anyone with some input I would appreciate it, I have been going
crazy for the last 9 hours because of a simple thing as tab color.

Thanks

Aug 10 '06 #2
C# using Excel Interop to get to Excel Objects

CODE USED:
NewXlsWkSht.Tab.ColorIndex = 35;

ERROR:
Cannot implicitly convert type 'int' to
'Microsoft.Office.Interop.Excel.XlColorIndex'

Aug 10 '06 #3
The problem here is that you are not supposed to set it to a value
representing a color. The allowable values are:

XlColorIndex.xlColorIndexAutomatic = -4105
XlColorIndex.xlColorIndexNone = -4142

Why aren't you setting the Color property instead?

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"ILProgrammer" <sw**********@sweettrouble.comwrote in message
news:11**********************@75g2000cwc.googlegro ups.com...
Hi I hope people are still talking in this group because I can't seem
to find any help on this. I am using Excel Interop and programming in
C#. I have Excel all setup and adding worksheets and everything, but
now I have a request from my users to change the tab color. Of course
they can do this manually and I was able to do it with the macro

CurrSht.Tab.ColorIndex = 4

but that doesn't work in C#. I keep getting an error about setting an
int to ColorIndex. I tried using CurrSht.Tab.Color = 4 and that does
change the tab color, but to black. No matter what number I use the
color is black.

Please anyone with some input I would appreciate it, I have been going
crazy for the last 9 hours because of a simple thing as tab color.

Thanks

Aug 10 '06 #4
I tried the Color property of tab as well. Trouble is no matter what
value I put there the tab is black.

CurrSht.Tab.Color = 35;

Maybe I am doing something wrong.
Do I need to set the index first to Automatic and then the Color???

Aug 10 '06 #5
OK nothing seems to be working here.

I can't set a value -4105 or anything to XlColorIndex. Unless I am
doing it wrong, how do you set that value?

Both these produce compile errors. . .

NewXlsWkSht.Tab.ColorIndex = -4105;
Microsoft.Office.Interop.Excel.XlColorIndex.xlColo rIndexAutomatic myInd
= -4105

All I can do without getting an error at compile is . . . but I get
errors during runtime on the colorindex line

NewXlsWkSht.Tab.ColorIndex =
Microsoft.Office.Interop.Excel.XlColorIndex.xlColo rIndexAutomatic;
NewXlsWkSht.Tab.Color = 35;

Either Excel's Interop no longer lets you change the tab color, or I am
doing and missing something. Anyone have more ideas to try?? Or can
see what I am doing wrong? Like I said no matter what number I put in
NewXlsWkSht.Tab.Color the color is black.

Thanks

Aug 11 '06 #6
YES finally. Thank you to everyone's responses. Through all of them I
was finally able to come up with a solution. To anyone ever trying to
change the colors to the tab on an Excel worksheet using C# and the
Excel Interop here is the code.

System.Drawing.Color myCol =
System.Drawing.Color.FromArgb(204,255,204);
int Clr = myCol.ToArgb();
NewXlsWkSht.Tab.Color = Clr;

Aug 11 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: dan glenn | last post by:
(PHP4.3.4, GD2) How can I save a PNG using GD2 and insure that it saves as a palette-based (8-bit, 256-color) single-color transparancy?? Saving this way, I could be sure that an image loaded from...
6
by: me | last post by:
good day, i found this message: and i want to know more about it too. ========================================== Hey all, example:...
19
by: Vinod | last post by:
Hi, I have got a peculiar requirement. I want to distinquish between the color codes. I have got two text fields and i will enter the color codes there. The first text field will have ...
11
by: Konrad Den Ende | last post by:
I have a function returning a string but the problem is that the color of it is blue which suits me well for some pages but not for others. Is it possible to "feel" what the color of the background...
5
by: AFN | last post by:
I'm trying to set a submit button to change text and color when clicked. Like saying "please wait" instead of "submit" and then changing the background color and text color. All works, except for...
15
by: | last post by:
Just about finished with an include modual that allows a user to select a color. Completely dynamic. all you have to do is include the script and run the main trigger script. One problem with...
3
by: Mickey | last post by:
Hi, I am having trouble with a javascript. The purpose of this script is to enable a user to click a generated color cell in a table and the color code ie: #ffffff is returned to the caller......
4
by: David Krmpotic | last post by:
Hello, Can please tell me how to do it ? This should be simple, because I'd think it's used a lot.. but in reality is not that simple and there is at least 50 topics about it in newsgroups,...
6
by: Mark | last post by:
Hello all - I'm trying to incorporate a stylesheet into an ASP.Net page but everytime I include the "LINK" code to the .css file in the HEADER location of the HTML code, the background color that...
7
by: Scott Schluer | last post by:
Is there a way to use the Image class to convert a color photo (GIF or JPEG) to a B&W photo? Thanks, Scott
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.