We help IT Professionals succeed at work.

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

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

Watch Question

Analyst Assistant
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


Thank you for the help!