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%"
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.