VBA在图纸上设置缩放级别 [英] VBA to set Zoom level on Sheets

查看:132
本文介绍了VBA在图纸上设置缩放级别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个VBA,它将根据屏幕分辨率设置缩放级别. 但是它仅在您打开工作簿时对ActiveWindow起作用. 如何在Excel中的所有工作表中添加它?

I have a VBA that will set the zoom level based on the screen resolution. But its working only for ActiveWindow when you open workbook. How can I add this across all worksheets in Excel?

Declare Function GetSystemMetrics32 Lib "user32" _
    Alias "GetSystemMetrics" (ByVal nIndex As Long) As Long

Public Sub ScreenRes()
    Dim lResWidth As Long
    Dim lResHeight As Long
    Dim sRes As String

    lResWidth = GetSystemMetrics32(0)
    lResHeight = GetSystemMetrics32(1)
    sRes = lResWidth & "x" & lResHeight
    Select Case sRes
        Case Is = "800x600"
            ActiveWindow.Zoom = 75
        Case Is = "1024x768"
            ActiveWindow.Zoom = 125
        Case Else
            ActiveWindow.Zoom = 100
    End Select
End Sub

我将在工作簿上调用此模块

I will call this module on the Workbook

Private Sub Workbook_Open()
ScreenRes
End Sub

推荐答案

基于@Jeeped答案,您可以在ThisWorkbook代码窗格中放置以下代码:

building on @Jeeped answer you could place in ThisWorkbook code pane the following code:

Declare Function GetSystemMetrics32 Lib "user32" _
    Alias "GetSystemMetrics" (ByVal nIndex As Long) As Long

Option Explicit

Private Sub Workbook_Open()
    With Worksheets
        .Select
        ActiveWindow.zoom = ScreenResToZoom
    End With
End Sub

Public Function ScreenResToZoom() As Long
    Select Case GetSystemMetrics32(0) & "x" & GetSystemMetrics32(1)
        Case Is = "800x600"
            ScreenResToZoom = 75
        Case Is = "1024x768"
            ScreenResToZoom = 125
        Case Else
            ScreenResToZoom = 100
    End Select
End Function

这篇关于VBA在图纸上设置缩放级别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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