Problem executing Excel macro from matlab

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 Comments

How are you trying to run it? Is it something that runs immediately and automatically when the workbook is opened? Are you using ActiveX to fire off the macro? Are you even using ActiveX at all? If so, what are your lines of code to run the macro.
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?
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?

Sign in to comment.

Answers (0)

Asked:

on 10 Jul 2015

Commented:

on 11 Jul 2015

Community Treasure Hunt

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

Start Hunting!