Excel 2007 VBA缩放(不使用select?)

时间:2022-11-19 23:35:36

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:

好的,所以我从来没有在VBA中做过任何需要激活工作表或选择单元格的事情。但是,现在,我正在尝试弄清楚如何在一堆工作表上进行100%缩放,我看到的所有代码(谷歌搜索结果,包括本网站的答案)似乎首先选择一张表:

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:

但是,我确实在OzGrid上找到了一些代码,这似乎意味着可以在不首先选择工作表的情况下执行此操作:

Sht.PageSetup.Zoom = 100

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

(虽然上面我们有Set Sht = ActiveSheet)我试过了

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 个解决方案

#1


3  

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


-1  

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.

设置Application.Screenupdating = False将无法解决您的问题。如果选择工作表或激活工作表Application.screenupdating将设置为true。

#1


3  

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


-1  

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.

设置Application.Screenupdating = False将无法解决您的问题。如果选择工作表或激活工作表Application.screenupdating将设置为true。