Using an Excel Macro from the PERSONAL.XLSB Workbook

3 ビュー (過去 30 日間)
Tim Starbuck
Tim Starbuck 2020 年 11 月 25 日
移動済み: Cris LaPierre 2023 年 3 月 2 日
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;

回答 (1 件)

jr1995
jr1995 2023 年 1 月 27 日
移動済み: Cris LaPierre 2023 年 3 月 2 日
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

カテゴリ

Help Center および File ExchangeDebugging and Analysis についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by