Cell background color change with Excel-DNA ???

1,060 views
Skip to first unread message

Zeeshan Akram

unread,
Jun 11, 2014, 6:30:08 AM6/11/14
to exce...@googlegroups.com
Hi,

I have an Excel-DNA Ribbon Add-in, in which I need to change the color of cells on sheets.
I know the Excel COM way to do this, but I want to know if there is something in Excel-DNA which would let me change cell colors easily?
any suggestions please...

Regards,
Zeeshan

Govert van Drimmelen

unread,
Jun 11, 2014, 6:47:04 AM6/11/14
to exce...@googlegroups.com

Hi Zeeshan,

 

I’d recommend using the COM object model for this kind of thing (modifying the sheet from a macro context).

From inside your Excel-DNA Ribbon callback you get hold of the root COM Application object by calling ExcelDnaUtil.Application.

If your project has a reference to the Excel interop assembly Microsoft.Office.Interop.Excel.dll (or you’ve added the Excel-DNA.Interop NuGet package) you can directly cast the result of  ExcelDnaUtil.Application to the Excel Application type. From there you use the object model as usual.

 

It would probably have more limited functionality in this case, but you could also use the C API call with the code xlcFontProperties to set the background. For details you’d need to consult the Excel macro help and look for FONT.PROPERTIES. Then you make the call from your Excel-DNA add-in using XlCall.Excel(XlCall.xlcFontProperties, …..)

 

You can download a .chm version of the macro help file here: http://www.xceed.be/Blog.nsf/dx/excel-macro-function-help-file-for-windows-7,

and a .pdf conversion of the whole file is here: https://www.codeplex.com/Download?ProjectName=exceldna&DownloadId=658244

 

Regards,

Govert

--
You received this message because you are subscribed to the Google Groups "Excel-DNA" group.
To unsubscribe from this group and stop receiving emails from it, send an email to exceldna+u...@googlegroups.com.
To post to this group, send email to exce...@googlegroups.com.
Visit this group at http://groups.google.com/group/exceldna.
For more options, visit https://groups.google.com/d/optout.

Zeeshan Akram

unread,
Jun 11, 2014, 8:18:59 AM6/11/14
to exce...@googlegroups.com

Hi Govert,

Thanks a lot for the advice.

Regards,
Zeeshan
Reply all
Reply to author
Forward
0 new messages