Is it possible to call Excel Macro Functions from MATLAB?
115 views (last 30 days)
You can execute Excel Macro functions from the MATLAB environment by using the ActiveX interface.
Here are two simple examples on how to call a Sub (in VB/VBA: a procedure without any returned values) and a Function (returns a value):
excelObject = actxserver('Excel.Application');
excelObject.Run('TestSub', 'Hello world');
retValue = excelObject.Run('TestFnc', 'Hello world from a function');
The Excel Macro routines that belong to this example (Test.xls) should be in a module and look as follows:
Public Sub TestSub(arg1 As String)
Public Function TestFnc(arg1 As String)
TestFnc = "Passed: " & arg1
More Answers (1)
Harris Ahmad on 10 Sep 2021
I am new to MATLAB and am confused as to where the MATLAB is designated the name of the Excel and the name of the macro. Or does this create a new macro? I am trying to run a macro from MATLAB that already exists in my Excel file.