change the color of a cell in excel spread sheet

pavansagar

Member
Joined
Jan 11, 2006
Messages
8
Programming Experience
Beginner
I am adding a excel office spreadsheet 11.0 com component.After loading the sheet I am able to add the color.But I am unable to add the color to a single cell through vb.net code at runtime. how to add the color to a cell from the code?

I also tried by adding references of microsoft excel 11.0 object library and microsoft office 11.0 object library.but I am not getting that.
please help me.
 
To apply formatting to a cell, you use the Interior object. For example,
ActiveCell.Interior.Pattern = xlSolid
sets the active cells background pattern to a solid.

Possible Property Names Color, ColorIndex, Pattern, PatternColor, PatternColorIndex,

With ActiveCell.Interior
.Color = RGB(0,0,255)
.Pattern = xlPatternHorizontal
.PatternColor = RGB(255,0,0)
End With

I assume if you are directly accessing a cell to place data in it you should be able to apply .interior.color at that time. Haven't tried this method.
 
thankyou.But I am getting a problem

sir,
I added the references Excel 11.0 and microsoft office 11.0. here I am declaring as 'dim wb as new excel.workbook'.

when I debugged this I am getting the strange error message as
"COM object with CLSID {00020819-0000-0000-C000-000000000046} is either not valid or not registered."

what does that mean?Also I didn't get the option 'activecell.interior.color'. It is 'worksheetobject.cells(rowindex,columnindex).interior.color' in my aplication.what is the application you are talking about?
please help me.
 
Excel Color Changes from VB.Net

Hi,

I have a follow-up question.

If I have a text box in a form with a user-defined color and I want to use the exact same color in a cell in Excel - how do I do that.

I already have everything set up where I can pick the correct cell and I can change it's text, but changing the color is the only thing left.

I know in VB.Net it uses names for colors but I don't know the conversion to excel.

Thanks in advance
 
Back
Top