Using an Excel Macro from the PERSONAL.XLSB Workbook

3 vues (au cours des 30 derniers jours)
Tim Starbuck
Tim Starbuck le 25 Nov 2020
Hi,
I have a script that generates an excel file for me and then a Macro that does all of the formatting of the file withing excel. I saved the Macro in My Personal Macro Workbook, and I would like to be able to call it from there and apply it to the excel file that I generate. We will call that file "WorkbookName.xlsx". I've seen that it is definitely possible to have MATLAB run a macro in excel on a specific workbook, but I can seem to figure out how to get it to pass my macro from the Personal Macro Workbook to my current workbook.
file_location = '\\myfilelocation\WorkbookName.xlsx';
ExcelApp = actxserver('Excel.Application');
% Open file
Workbook = ExcelApp.Workbooks.Open(file_location);
% Show window (optional).
ExcelApp.Visible = 1;
% Run WAD_Formatting macro from Personal Macro Workbook,
ExcelApp.Run('PERSONAL.XLSB!.WAD_Formatting');
% Quit application and release object.
ExcelApp.Quit;
ExcelApp.release;

Réponses (1)

jr1995
jr1995 le 27 Jan 2023
Déplacé(e) : Cris LaPierre le 2 Mar 2023
Hi,
the following code worked for me. Beside the file I would work on, I also opened my personal workbook. Then I could execute the embedded macros.
%testing with excel
ExcelApp = actxserver('Excel.Application');
ExcelApp.Workbooks.Open("path_to_personal_macro_workbook\PERSONAL.XLSB"); %Import personal macros
excelWb=ExcelApp.Workbooks.Open("path_to_excel_table.xlsx"); % Open up the workbook named in the variable fullFileName.
ExcelApp.Visible = true; %Make workbook visible
ExcelApp.Run('PERSONAL.XLSB!MethodName'); %Run arrhenius macro

Catégories

En savoir plus sur Debugging and Analysis dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by