Excel 2007 VBA缩放(不使用选择?) [英] Excel 2007 VBA Zooming (without using select?)

查看:265
本文介绍了Excel 2007 VBA缩放(不使用选择?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,所以我从来没有在VBA中做任何事情,因为我需要激活一个工作表或选择一个单元格。但是,现在,我正在试图找出一些工作表中的缩放到100%,而我看到的所有代码(谷歌的结果,包括本网站的答案)似乎首先选择了一个工作表:

  ActiveWindow.Zoom = 100 

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

  Sht.PageSetup.Zoom = 100 

(虽然上面我们有Set Sht = ActiveSheet)尝试做

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

但没有发生任何事情...字面上没有。



解决方案

是的,我相信缩放只是对活动工作表有影响。



但是,如果您不想看到每个工作表被激活并缩放,就会发生可以添加行

  Application.ScreenUpdating = False 

在您的缩放代码之后,然后完成:

  Application.ScreenUpdating = True 


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.

解决方案

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

这篇关于Excel 2007 VBA缩放(不使用选择?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆