MATLAB: How to set excel cell color to red from Matlab

cellcolorexcel

According to excel color index, the color index for red is 3.
In VBA, I can easily set red color, but in matlab code, I tried different numbers for Interior.ColorIndex, never got red color.
Anyone can tell me why? Thanks a lot.
-Derek

Best Answer

This works for me:
% Connect to Excel
Excel = actxserver('excel.application');
% Get Workbook object
WB = Excel.Workbooks.Open(fullfile(pwd, 'Book1.xlsx'),0,false);
% Set the color of cell "A1" of Sheet 1 to RED
WB.Worksheets.Item(1).Range('A1').Interior.ColorIndex = 3;
% Save Workbook
WB.Save();
% Close Workbook
WB.Close();
% Quit Excel
Excel.Quit();