Unable to change font and background color of excel cells using vb.net application

V Nadeau
V Nadeau used Ask the Experts™
on
Hi. I am trying to change the font, the font size and color of a cell in an excel worksheet from my vb.net application.

The first two lines of code run without errors but do not change anything in the cells. The third line, to change the color, gives me the following error at runtime: "System.Runtime.InteropServices.COMException: 'Type mismatch. (Exception from HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH))'"

The workbook is open to not read-only and is editable, in fact, the same cells will add values.

Here is my code:

'Format formula cell to match font and size of existing cells
                ForcastWorkSheet.Cells.Range(strRange).Font.Name = "Arial"
                ForcastWorkSheet.Cells.Range(strRange).Font.Size = "9"
                ForcastWorkSheet.Cells.Range(strRange).Interior.Color = "Orange, Accent 2, Lighter 60%"

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Analyst Assistant
Commented:
Color in Excel is numerical, you can't use the 'description'.

For that particular shade of orange try this.
 ForcastWorkSheet.Cells.Range(strRange).Interior.Color  = 11389944

Open in new window

Author

Commented:
Thank you for the help!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial