필터 지우기
필터 지우기

run excel macro from simulink

조회 수: 1 (최근 30일)
Lau Boon Chong
Lau Boon Chong 2019년 12월 18일
댓글: Kavya Vuriti 2020년 3월 30일
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
Lau Boon Chong
Lau Boon Chong 2019년 12월 19일
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 2020년 3월 30일
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.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Import from MATLAB에 대해 자세히 알아보기

태그

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by