[英]Excel VBA Code to Force a certain zoom level
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.谢谢。
If (ActiveWindow.Zoom < 100) Then
ActiveWindow.Zoom = 100
End If
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
To address returning to the default previous zoom level (and prevent unnecessary zoom flickering I suggest:为了解决返回到默认的先前缩放级别(并防止不必要的缩放闪烁,我建议:
'Assumed default zoom level= 70
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim Temp As Byte
Temp = 0
If Not Intersect(Target, Range("G3:H9999")) Is Nothing Then
If ActiveWindow.Zoom <= 70 Then ActiveWindow.Zoom = 100
Temp = 1
End If
If Not Intersect(Target, Range("E2:E9999")) Is Nothing Then
If ActiveWindow.Zoom <=70 Then ActiveWindow.Zoom = 100
Temp = 1
End If
If Temp = 0 And ActiveWindow.Zoom = 100 Then ActiveWindow.Zoom = 70
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.