Problem executing Excel macro from matlab

1 Ansicht (letzte 30 Tage)
Nitza Burck
Nitza Burck am 10 Jul. 2015
Kommentiert: Image Analyst am 11 Jul. 2015
Hi,
I'm doing a project that inputs an excel file, does some modifications on it, exports to a new one.
Everything works, up until I try to access a macro in my output file, then I get this:
Error using Interface.Microsoft_Excel_14.0_Object_Library._Application/Run Invoke Error, Dispatch Exception: Source: Microsoft Excel Description: Cannot run the macro 'Macro1'. The macro may not be available in this workbook or all macros may be disabled. Help File: xlmain11.chm Help Context ID: 0
Error in TEST (line 49) invoke(app,'Run','Macro1');
When I try to give it a fully qualified name, it changes the error to complaining
Error using Interface.Microsoft_Excel_14.0_Object_Library._Application/Run Invoke Error, Dispatch Exception: Source: Microsoft Excel Description: 'C:\Users\nitza\Documents\PERSONAL.XLSB' could not be found. Check the spelling of the file name, and verify that the file location is correct.
If you are trying to open the file from your list of most recently used files, make sure that the file has not been renamed, moved, or deleted. Help File: xlmain11.chm Help Context ID: 0
Error in TEST (line 49) invoke(app,'Run','PERSONAL.XLSB!Macro1');
Now, the macro is defined in something called "Personal.xlsb", my file is "output.xlsb". The attachment shows how excel has arranged it.
How do I access the macro? Thanks.
  3 Kommentare
Nitza Burck
Nitza Burck am 10 Jul. 2015
Bearbeitet: Nitza Burck am 10 Jul. 2015
Hi, Thank you for your fast response. my code is:
if true
% code
end
filename='output.xlsb';
xlswrite(filename,array_ltr); %printing array to nex excel sheet
Excel = actxserver('excel.application');% Connect to Excel
Excel.Visible=1;
WB = Excel.Workbooks.Open(fullfile(pwd, 'output.xlsb'),0,false);% Get Workbook object
Excel.Workbooks.Item(1).RunAutoMacros(1);
app=WB.Application;
activesheet = Excel.Activesheet;
invoke(app,'Run','Macro1');
WB.Save();% Save Workbook
WB.Close();% Close Workbook
Excel.Quit();% Quit Excel
(might be a bit messy since I tried many variation attempting to make this run).
Do you have any idea what is the problem?
Image Analyst
Image Analyst am 11 Jul. 2015
What is an xlsb file? I only use xlsx files. If you attach your workbook, people can try the code.
When you open it in Excel, it doesn't have a yellow banner at the top with a button that say "Enable editing" does it?

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Use COM Objects in MATLAB finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by