Excel 2007 VBA Zooming (without using select?)

2019-07-19 16:23发布

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.

2条回答
劫难
2楼-- · 2019-07-19 16:31

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
查看更多
等我变得足够好
3楼-- · 2019-07-19 16:41

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.

查看更多
登录 后发表回答