Excel ActiveX slow and stealing focus

For several years now I'm using an activex server to export data to Excel spreadsheets. I recently upgraded to Matlab R2022b and since then there are two annoying things to this:
  • Saving the workbook has become slower
  • Saving the workbook shows a progress popup which steals the focus from all other applications running
I guess I can live with the slowdown (though suggestions to improve this are welcome), but the focus stealing makes it impossible to let my program run in the background. Can I somehow disable or work around the focus stealing behaviour?
I'm using the activex server somewhat like this:
hExcel = actxserver('excel.application');
for file = 1:many
hWorkbook = hExcel.Workbooks.Add();
% export data and formatting to worksheet
%
hWorkbook.SaveAs("TheFileName"); % This is where the popup happens
hWorkbook.Close(false);
end
hExcel.Quit;
hExcel.delete;
Update:
Just now noticed a question mark on the popup, which redirects me to this Microsoft support page. The title of the popup I see is "saving", so I looked at the "Opening or daving files" section. Although there are no external references as far as I know, just to be sure I added:
hWorkbook = hExcel.Workbooks.Add();
hWorkbook.UpdateRemoteReferences = false;
hWorkbook.UpdateLinks = 2; % xlUpdateLinksNever == 2 Embedded OLE links are never updated for the specified workbook
But that does not help.

Answers (2)

What is the visibility property? Try making it invisible right after you get it.
hExcel.Visible = false;
or something like that.

7 Comments

Thanks.
The Property hExcel.Visible already has the value 0. Explicitly setting it to false makes no difference.
This did make me look at other properties. I tried setting the following to false:
hExcel.ScreenUpdating = false;
hExcel.DisplayAlerts = false;
but that also makes no difference.
Try not using SaveAs method. Use MATLAB's copyfile to make a copy of some template workbook (with all the formatting you desire in it) then use the .Open method to open that existing workbook. Then toss your data in and don't use SaveAs to save it -- use Save instead to save the currently active workbook.
Unfortunately that also does not prevent the popup from being shown.
I have an empty file that I copy to the target filename. I open that file, put my data in, and used Save() to store the file. Still the popup is being shown.
OK, you're using Microsoft Office 365, which is a web based version. If you do that, it will ask you to login. On our company computers what was required was that we start an office app by itself and then login. Then Office would ask something like "Do you want to automatically login every time instead of asking each and every time. Once we said to do that the pop up didn't happen anymore. An alternative is you can get a version of Office that is completely local. It's called something like an extended service plan. I think it's good for some number of years, like 3 or 5 or 10. If you can get that, it should be the same as before they moved to web based office.
Huh, interesting. Basically, that help page link is wrong or I'm running multiple versions of Office? As far as I know I'm on Office 19. But the point is moot, I'm on a computer managed by corporate, so changing Office versions is out of my scope...
What do you see if you just start Excel by itself, without starting MATLAB? Does it ask you to login?
Can you ask your IT people if they can get a standalone version of Office that doesn't require you to login? With our IT, they could.
There's no login prompt, it just starts.
I think I already have a standalone version, but I'll double check with IT.

Sign in to comment.

Jan
Jan on 24 Jul 2023
Apparently this is caused by saving to a network drive. I worked around it by first saving the Excel worksheet to a local temporary file, then copying the file to the final destination.
Now the popup is no longer shown, and as a bonus it is also faster. Win-win for me ;)

Products

Release

R2022b

Asked:

Jan
on 19 Jul 2023

Answered:

Jan
on 24 Jul 2023

Community Treasure Hunt

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

Start Hunting!