Excel 2007 VBA Zooming (without using select?)

[亡魂溺海] 提交于 2019-12-11 02:56:57

问题


Okay, so I've never had to do anything in VBA where I was REQUIRED to activate a sheet or select a cell. But, now, I'm trying to figure out how to do Zoom to 100% on a bunch of worksheets, and all the code I see (google results, including answers from this website) seems to select a sheet first:

ActiveWindow.Zoom = 100 

But, I did find some code on OzGrid that seems to imply it's possible to do it without selecting a sheet first:

Sht.PageSetup.Zoom = 100

(although above we have Set Sht = ActiveSheet) I tried doing

Set Sht = ThisWorkbook.Worksheets("Sheet1")
Sht.PageSetup.Zoom = 150

but nothing happens... literally nothing.

So, is this possible? Or must I activate a worksheet before I can do the zooming? I've read so many times that this is bad programming practice, unless you absolutely have to.


回答1:


Yes, I believe zooming is something that only has an effect on an active sheet.

However, if you didn't want to 'see' each sheet getting activated and zoomed as it happens, you could add the line

Application.ScreenUpdating = False

before your zoom code and then after it is done:

Application.ScreenUpdating = True



回答2:


Setting Application.Screenupdating = False will not solve your problem. If you select a sheet or activate a sheet Application.screenupdating will be set to true.



来源:https://stackoverflow.com/questions/9414426/excel-2007-vba-zooming-without-using-select

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!