Home » excel » Set Excel Zoom from MATLAB using ActiveX

Set Excel Zoom from MATLAB using ActiveX

Posted by: admin April 23, 2020 Leave a comment


By default the Excel zoom is 100% on all sheets.
I am trying to change the zoom of Sheet1 to 80% using ActiveX from MATLAB.

Here is the code I tried, it did not give any error but the zoom remains unchanged.

Excel = actxserver('Excel.Application');
WB = Excel.Workbooks.Add;
Sheets = Excel.ActiveWorkbook.Sheets;
Sheet1 = Sheets.get('Item',1);
Sheet1.PageSetup.Zoom = 80;
WB.SaveAs([pwd, '\test.xls'])

Does the code miss something ?

How to&Answers:

If you try to change the display zoom you are looking for this command:

Excel.ActiveWindow.Zoom = 80;

The PageSetup zoom applies when printing the worksheet.