run excel macro from simulink

1 Ansicht (letzte 30 Tage)
Lau Boon Chong
Lau Boon Chong am 18 Dez. 2019
Kommentiert: Kavya Vuriti am 30 Mär. 2020
Hi All
I try to use MATLAB Function block to run Excel macro by using MATLAB Function block in Simulink. Below is my code:
function duty = fcn()
duty = zeros(1,1);
coder.extrinsic('actxserver')
excel = actxserver('Excel.Application')
excel.Workbooks.Open('D:\pso.xlsm')
excel.Run('Sheet1.run_pso');
excel.Quit;
end
However, error pop out as shown below:
Attempt to extract field 'Workbooks' from 'mxArray'.
Anyone can help me? Thank you.
  3 Kommentare
Lau Boon Chong
Lau Boon Chong am 19 Dez. 2019
Hi, thank for answer my question. However, the problem still remain after modified the code as suggested. Anyway, how to initialize Workbooks?
Kavya Vuriti
Kavya Vuriti am 30 Mär. 2020
Hi,
The error given arises when there are variables which are not initialized and assigned directly. I think the following code must work:
Workbook = excel.Workbooks.Open('D:\pso.xlsm');
excel.Run('Sheet1.run_pso');
excel.Quit;
If the error persists, could you share the excel file with the macro.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu MATLAB Functions in Microsoft Excel finden Sie in Help Center und File Exchange

Produkte


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by