MATLAB: Excel’s named range through Matlab

excel

Hello,
I have an Excel file which uses excel named range (I've gave the named range prior to using Matlab). I use xlsread(file,sheet,'RangeName',mode,customFun) to read the named range which is called – 'RangeName'. Now I would like to create Excel file through Matlab using xlswrite, then to write values to several cells and give them name, meaning give those cells a named range. How do I do that through Matlab?
Thank you!

Best Answer

Hi,
this is not possible using xlswrite. You have to do that programatically afterwards using COM/ActiveX, e.g.
ex = actxserver('excel.application');
ex.Workbooks.Open(fullfile(pwd,'Mappe1.xlsx'));
ex.Range('A1:C3').Name = 'RangeName';
ex.ActiveWorkbook.Save
ex.Quit
ex.release
So do a xlswrite to write down the data and afterwards create the named ranges.