vba 在定义的缩放级别设置所有 Excel 工作表

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5953703/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 11:29:00  来源:igfitidea点击:

Setting all Excel sheets at a defined zoom level

excelvbaexcel-2010

提问by Regmi

I have more than twenty sheets in an Excel workbook (file). Is there some code snippet or a command I could apply/use so that all sheets could be reset to let's say 85% zoom level?

我的 Excel 工作簿(文件)中有二十多张纸。是否有一些代码片段或我可以应用/使用的命令,以便可以将所有工作表重置为 85% 缩放级别?

回答by Alex P

Sub SetZoom()
    Dim ws As Worksheet

    For Each ws In Worksheets
        ws.Select
        ActiveWindow.Zoom = 85 ' change as per your requirements
    Next ws
End Sub

BTW, if you simply select all worksheets in your workbook using the tabs you can then set the zoom to 85% and it will apply to all worksheets

顺便说一句,如果您只是使用选项卡选择工作簿中的所有工作表,则可以将缩放比例设置为 85%,它将应用于所有工作表

回答by Felipe Ribeiro

Sub SetZoom()

Dim ws As Worksheet
Application.ScreenUpdating = False    'Optional
For Each ws In ActiveWorkbook.Worksheets
    ws.Activate
    ActiveWindow.Zoom = 85
Next
Application.ScreenUpdating = True

End Sub

This code is similar from the above, but it is not necessary to select all worksheets in your workbook before running the macro. Instead of using ws.Selectand Next wsthat not work correctly unless you select the worksheets, change to ws.Activateand Nextto set the zoom for all the sheets. As optional, the ScreenUpdatingcan be disabled for a workbook with a lot of sheets.

此代码与上面的代码类似,但在运行宏之前不必选择工作簿中的所有工作表。除非您选择工作表,否则使用ws.SelectandNext ws不能正常工作,而是更改为ws.ActivateNext设置所有工作表的缩放。作为可选,ScreenUpdating可以禁用包含大量工作表的工作簿。

回答by Ardus

Option Explicit

Sub FixSheets()
    Dim ws As Worksheet
    For Each ws In Worksheets
        ws.Activate
        ws.UsedRange.Select
        ActiveWindow.Zoom = True 'Zoom sur la sélection
        ActiveCell.Select
    Next ws
End Sub