LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I change the background color of a cell in Excel using Active X in LabWindows/CVI?

How can I change the background color of a cell in Excel using Active X in LabWindows/CVI?
0 Kudos
Message 1 of 2
(4,177 Views)
Color changing is not very intuitive in Excel ActiveX programming.

1) First you would get a range object of the effective range you wanted to change.

2) The using the GetProperty function to get a reference to the Interior property of the range.

3) Finally, us the SetProperty function to set the ColorIndex property of the Interior to a color index from the Excel color palette.

For example, something like:

error = Excel_WorksheetRange (ExcelWorksheetHandle, NULL, MyCellRangeV, CA_DEFAULT_VAL, &ExcelRangeHandle);
error = Excel_GetProperty (ExcelRangeHandle, &ErrorInfo,Excel_RangeInterior, CAVT_OBJHANDLE, &ExcelInteriorHandle);
error = Excel_SetProperty (ExcelInteriorHandle, &ErrorInfo, Excel_InteriorColorIndex, CAVT_VARIANT, CA_VariantLo
ng (5));

where, MyCellRangeV is a variant that contains a range string (i.e. "A1:B5") and 5 is the index of the color in Excel's color palette. 5 should be blue.

Remember to discard all of your object handles to Excel objects (ExcelWorksheetHandle, ExcelRangeHandle, ExcelInteriorHandle) so that Excel will shutdown properly.

Best Regards,

Chris Matthews
National Instruments
Message 2 of 2
(4,177 Views)