- It may not be loaded yet.
- Even if installed, it may not be loaded in the Excel instance that MATLAB created.
- Macros from add-ins require fully qualified names, including the filename.
Running macro within vba project from Matlab
7 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hi, I'm using this script in matlab, it works perfect:
excelObject = actxserver('Excel.Application');
excelObject.Workbooks.Open('C:\Test.xls');
excelObject.Run('Module1');
Now this has the macro saved inside the workbook so it can easily find the macro and run it.
I have a 'excel add-in' which is stored in the add ins section of Office, it contains a macro that I want to run using matlab. How can I refer to this macro because whenever I run it matlab says it cannot find the macro
Thanks,
0 Commenti
Risposte (1)
Aniket
il 8 Apr 2025
This is a common issue when working with Excel add-ins (.xlam files) from MATLAB.
MATLAB interacts with Excel using the COM interface. When you open a workbook that contains a macro, it's scoped and active, so Module1.MacroName is enough. But with an add-in:
Please use the below updated code for using add-ins:
excel = actxserver('Excel.Application');
addinPath = 'C:\MyAddIns\MyAddin.xlam';
excel.Workbooks.Open(addinPath); % Open it just like a workbook
% Run your macro — use the fully-qualified macro name
% Format: 'MyAddin.xlam!ModuleName.MacroName'
% e.g., If inside Module1, you have a macro called HelloWorld
excel.Run('MyAddin.xlam!Module1.HelloWorld');
Note: Excel uses the filename of the add-in (not display name) in the macro reference.
0 Commenti
Vedere anche
Categorie
Scopri di più su Use COM Objects in MATLAB in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!