- Use the search box at the top of Task Manager to search for "excel" and confirm that only one Excel process is active. This ensures that you connect to the intended target workbook.
- You can also use the following MATLAB code to programmatically check how many Excel processes are running before running script:
How can I paste a MATLAB figure into an existing Excel file using MATLAB R2025a on Windows?
5 views (last 30 days)
Show older comments
MathWorks Support Team
on 26 Nov 2025 at 0:00
Answered: MathWorks Support Team
on 2 Dec 2025 at 21:45
I am trying to automate the process of plotting and pasting a MATLAB figure into an already open Excel file using MATLAB R2025a on Windows. I want to make sure I connect to the correct Excel process and avoid errors when using the "actxGetRunningServer" function. I am currently using Microsoft Excel for Microsoft 365, Version 2509 (64-bit). How can I reliably paste my figure into the Excel workbook?
Accepted Answer
MathWorks Support Team
on 26 Nov 2025 at 0:00
Using COM to connect to Excel is a great way to accomplish this. Note that this approach will not work for non-Windows machines, since COM is used.
An Excel process may have multiple workbooks and worksheets open simultaneously. Before running your MATLAB code, make sure that only the specific workbook you want to use is open, and that the desired worksheet is active - that is, selected and visible above any other worksheets. The script relies on the correct workbook and worksheet being active in order to paste the figure into the intended location.
Attached is a simple script ("excel_figure_demo.m") that shows how one can connect to the Excel spreadsheet and add a figure from MATLAB.
Before running the script, make sure only one Excel process is running:
>> [~, result] = system('tasklist /FI "IMAGENAME eq EXCEL.EXE"');
>> numExcelProcesses = count(result, 'EXCEL.EXE');
>> disp(['Number of Excel processes running: ', num2str(numExcelProcesses)]);
Note: The script above was tested and verified using MATLAB R2025a, and Microsoft Excel for Microsoft 365, Version 2509 (64-bit).
0 Comments
More Answers (0)
See Also
Categories
Find more on Spreadsheets in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!