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
Setting all Excel sheets at a defined zoom level
提问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.Select
and Next ws
that not work correctly unless you select the worksheets, change to ws.Activate
and Next
to set the zoom for all the sheets. As optional, the ScreenUpdating
can be disabled for a workbook with a lot of sheets.
此代码与上面的代码类似,但在运行宏之前不必选择工作簿中的所有工作表。除非您选择工作表,否则使用ws.Select
andNext ws
不能正常工作,而是更改为ws.Activate
和Next
设置所有工作表的缩放。作为可选,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