Call Excel cell contents for series name using ActiveX

3 views (last 30 days)
I am attempting to create a multi-series chart in Excel using the MATLAB ActiveX feature and I have almost all of it, except for being able to name the series. The difficulty with this is that I am attempting to automate the selection process by getting MATLAB to reference some of the Excel cells for the name choice.
More specifically I have having issues with the incompatibility of the naming command, which requires a string input, and the calling reference, which results an interface handle.
xlsheet = Excel.ActiveSheet;
xlchart = xlsheet.ChartObjects.Add();
% Series name calling line
name = xlsheet.Range('C2');
% Series name declaration line
xlchart.Chart.SeriesCollecition(1).Name = name;

Answers (1)

Bob Thompson
Bob Thompson on 8 Aug 2016
After much research, and trial and error. It is possible to use the contents of an excel cell as a string by using .Value at the end of the calling.
seriesname = xlsheet.Range(Range_here).Value;
xlchart.Chart.SeriesCollection(1).Name = seriesname;
This is assuming that the contents of the cell being called are a string.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!