强制特定缩放级别的 Excel VBA 代码
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9062213/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Excel VBA Code to Force a certain zoom level
提问by Ckeane
I have a Validated Dropdown list in Excel that is unreadable if zoom is less than 100. I checked on the internet and fvound that I can not alter the size of the Validated list text size so I want to enforce a set zoom of 100.
我在 Excel 中有一个验证下拉列表,如果缩放小于 100,则无法读取该列表。我在互联网上查看并发现我无法更改验证列表文本大小的大小,因此我想强制设置缩放为 100。
I have the code to do this as follows
我有代码来做到这一点如下
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
ActiveWindow.Zoom = 100
End Sub
This works and is fine for people who use zoom less than 100, but if people use a greater than 100 zoom it restricts the zoom to 100. Is there a way to overcome this, something along the lines of an If-Else statement.
这适用于使用小于 100 的缩放比例的人,但如果人们使用大于 100 的缩放比例,它会将缩放比例限制为 100。有没有办法克服这个问题,类似于 If-Else 语句。
If zoom less than 100 then zoom = 100 else if zoom greater than 100 do nothing
如果缩放小于 100 则缩放 = 100 否则如果缩放大于 100 什么都不做
Thanks.
谢谢。
回答by Steven
If (ActiveWindow.Zoom < 100) Then
ActiveWindow.Zoom = 100
End If
回答by JimmyPena
Here's a one-liner that will do the same thing:
这是一个单线,可以做同样的事情:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
ActiveWindow.Zoom = Application.Max(ActiveWindow.Zoom, 100)
End Sub