how to run a Macro from excel in MATLAB

42 views (last 30 days)
JULIO ROMAN
JULIO ROMAN on 15 Mar 2019
Answered: Girish babu P on 26 Feb 2020
Hello ,
i have a macro in excel programed in Visual Basic. I need to run it from MATLAB or coding it again in MATLAB language. How can i do it automatically?
I have MATLAB R2013b
Thank you so much!

Answers (2)

Guillaume
Guillaume on 15 Mar 2019
Edited: Guillaume on 15 Mar 2019
It's going to be something like:
excel = actxserver('Excel.Application');
excel.Workbooks.Open('C:\somewhere\someexcelfilewithmacro.xlsx')
excel.Run('NameOfMacro');
excel.Quit; %when done
Of course, it's likely that you need more but with so little details it's unknown what that would be.
"or coding it again in MATLAB language".
There's no translator form VB to matlab. You'll have to write the code yourself.
However, this begs the question: why don't you run the macro directly from excel since it's already working there.
  1 Comment
JULIO ROMAN
JULIO ROMAN on 15 Mar 2019
Thank you Guillaume!
i want to do a proyect more ambitious and the basic algorith of my project is made in the macro.
I am trying to do a model for troubleshooting. I have a system made by contactors, but that contactor usually fail. The aim is to introduce amount of real data in the model and it will tell me when and which contactor failed.
The contactors close and open with a logic, and that logic is implemented in the macro. That logic is the basis of my project.
It would be perfect if i could introduce my real datas into the Macro from matlab and it tell me the theorical output, so i could compare with the real output.
The logic of my contactors could be gather into a truth table so , maybe, it also work if i could generate automatically a truth table introducing all the posibilities in the macro. It's imposible to do in a manual way becouse there are 10 inputs and 24 outputs.
Any help or idea are welcome!
thank you.

Sign in to comment.


Girish babu P
Girish babu P on 26 Feb 2020
ExcelApp = actxserver('Excel.Application');
ExcelApp.Visible = 1;
ExcelApp.Workbooks.Open(fullfile(pwd,'\filename.xls'));
ExcelApp.Run('ThisWorkBook.Macro1');
ExcelApp.Quit;
ExcelApp.release;

Categories

Find more on Data Import from MATLAB in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!