Open MS Excel from Matlab
Is there a way to make Matlab open Excel files directly in MS Excel? I don't want to just read the data, but physically open MS Excel. I have a script that processes some data and stores it in .xlsm. This .xlsm contains the auto_open macro that generates the report and saves it to another .xls. I want the process to be as automatic as possible. For now, when the matlab script ends, the .xlsm file has to be opened manually. Can this be done via Matlab? (The .m and .xlsm file are in the same folder.)
source to share
Excel has a powerful COM interface that allows you to control it from another application.
See here where the Maclab side is.
http://www.mathworks.co.uk/help/techdoc/ref/actxserver.html
And here's an example to put it all together ...
https://www.quantnet.com/forum/threads/interface-between-matlab-vba-excel.2090/
or here's another example
http://www.mathworks.co.uk/support/solutions/en/data/1-716EAM/index.html?solution=1-716EAM
source to share
Yes it is possible. Matlab can use the Excel Automation interface for this and similar tasks. The following code loads Excel and then loads the workbook:
try
w = actxserver('Excel.Application'); % Fails if Excel not installed
catch
w = [];
end
if ~isempty(w)
w.Workbooks.Open('D:\Documents\MATLAB\file.xlsx');
% Your code here;
w.Quit;
end
delete(w);
You will need to look at the Microsoft documentation for the Excel Automation interface to determine exactly what commands you need to send. Try running here . I used this technique to drive Word from Matlab to create a reporting document, but I have never used Excel this way, so unfortunately I cannot help you with gory details!
source to share