How can I run different Excel Macros buttons from MATLAB?
10 次查看(过去 30 天)
显示 更早的评论
I currently have a large excel file connected to a macros script. Within the excel file, there are 2 different buttons to run different variations of the same macros. Whenever I run the macros from MATLAB, it only runs the first button. My question is, is there a way that I can specify which button I want to push from MATLAB? For more background information, I am using an excel spreadsheet provided by the FAA, which can be found at: https://www.fire.tc.faa.gov/Systems/FuelTank/FTFAM. I would like to be able to differentiate between "Run Monte Carlo" and "Run Single Flight.
Thanks for the help
1 个评论
Saurabh Singhal
2023-3-1
Hi. Were you able to figure this out? I am trying to achieve something similar but don't know how to.
Thanks.
回答(1 个)
DUY Nguyen
2023-3-2
I found this with Chatgpt. You can try this:
"Yes, it is possible to specify which button to click in an Excel file using MATLAB. You can use the actxserver function in MATLAB to connect to Excel and then use the InvokeVerb method to activate the desired button. Here is some sample code that you can modify to fit your specific Excel file and macros:
% Start an ActiveX server for Excel
excel = actxserver('Excel.Application');
% Open your Excel file
workbook = excel.Workbooks.Open('C:\path\to\your\file.xlsx');
% Select the worksheet where your buttons are located
worksheet = workbook.Worksheets.Item('Sheet1');
% Get a reference to the "Run Monte Carlo" button
button1 = worksheet.Buttons.Item('Button 1');
% Get a reference to the "Run Single Flight" button
button2 = worksheet.Buttons.Item('Button 2');
% Invoke the "Run Monte Carlo" button
button1.InvokeVerb('LeftClick');
% Invoke the "Run Single Flight" button
button2.InvokeVerb('LeftClick');
% Close the workbook and quit Excel
workbook.Close;
excel.Quit;
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!