how to run a Macro from excel in MATLAB

41 visualizaciones (últimos 30 días)
JULIO ROMAN
JULIO ROMAN el 15 de Mzo. de 2019
Respondida: Girish babu P el 26 de Feb. de 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!

Respuestas (2)

Guillaume
Guillaume el 15 de Mzo. de 2019
Editada: Guillaume el 15 de Mzo. de 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 comentario
JULIO ROMAN
JULIO ROMAN el 15 de Mzo. de 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.

Iniciar sesión para comentar.


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

Categorías

Más información sobre Data Import from MATLAB en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by