Using an Excel Macro from the PERSONAL.XLSB Workbook

3 visualizzazioni (ultimi 30 giorni)
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;

Risposte (1)

jr1995
jr1995 il 27 Gen 2023
Spostato: Cris LaPierre il 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

Categorie

Scopri di più su Debugging and Analysis 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!

Translated by