VBA代码会根据工作表中的文本/对象更改缩放级别?

发布于 2025-02-04 03:26:51 字数 853 浏览 2 评论 0原文

总而言之,

我一直在寻找实现以下功能的VBA代码:

  1. 对于包含特定关键字的工作表的缩放为80%
  2. ,该工作表将包含图片设置的工作
  3. 表Zoom设置为 60%这里的关键词

是我一直试图操纵以适应这一特殊挑战的代码,我的非代码注释指示我想更改什么:

Sub ZoomSheets() 
   Dim ws As Worksheet  
    Application.ScreenUpdating = False 
    For Each ws *with a picture* In Worksheets 
        ws.Activate
        ActiveWindow.Zoom = 60
    Next
    For Each ws *that contains X text* In Worksheets 
        ws.Activate
        ActiveWindow.Zoom = 80
    Next
    For Each ws *that contains Y text* In Worksheets 
        ws.Activate
        ActiveWindow.Zoom = 85
    Next
    Application.ScreenUpdating = True
    End Sub

对于我的工作中的某些可交付方式,经理喜欢在Excel中的某些床单工作簿的不同缩放水平取决于纸张的包含的内容:如果有图片,则为60%,如果在顶部说“ Y”,则为85%,如果顶部为“ X”,则为80%。我已经能够找到在所有表上设置均匀缩放的VBA代码,但是我正在寻找帮助编写更灵活的代码,并可以根据表所包含的内容来更改变焦。

谢谢你!

All,

I've been looking for VBA code that achieves the following:

  1. Sets zoom to 80% for worksheets that contain a certain key word
  2. Sets zoom to 60% for worksheets that contain a picture
  3. Sets zoom to 85% for worksheets that contain a different key word

Here is the code that I have been trying to manipulate to suit this particular challenge, with my non-code comments indicating what I'd like to change:

Sub ZoomSheets() 
   Dim ws As Worksheet  
    Application.ScreenUpdating = False 
    For Each ws *with a picture* In Worksheets 
        ws.Activate
        ActiveWindow.Zoom = 60
    Next
    For Each ws *that contains X text* In Worksheets 
        ws.Activate
        ActiveWindow.Zoom = 80
    Next
    For Each ws *that contains Y text* In Worksheets 
        ws.Activate
        ActiveWindow.Zoom = 85
    Next
    Application.ScreenUpdating = True
    End Sub

For a certain deliverable at my job, the manager prefers certain sheets within an excel workbook to be at different zoom levels depending on what the sheet contains: 60% if there is a picture, 85% if it says "Y" at the top and 80% if it says "X" at the top. I've been able to find VBA code that sets a uniform zoom across all sheets, but I am looking for help writing code that is a little more flexible and allows me to vary the zoom depending on what the sheet contains.

Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你怎么敢 2025-02-11 03:26:51
Sub ZoomSheets()

    Application.ScreenUpdating = False

    Dim ws As Worksheet
    Dim checkRng As String: checkRng = "A1:ZZ999"
    Dim picture As Variant
    For Each ws In ThisWorkbook.Worksheets
    
        With ws.Range(checkRng)
            If Not .Find("epic", LookIn:=xlValues) Is Nothing Then
                ws.Activate
                ActiveWindow.Zoom = 90
            ElseIf Not .Find("poggers", LookIn:=xlValues) Is Nothing Then
                ws.Activate
                ActiveWindow.Zoom = 80
            Else
                For Each picture In ws.Pictures
                    If picture.Name Like "*Picture*" Then
                        ws.Activate
                        ActiveWindow.Zoom = 70
                        Exit For
                    End If
                Next
            End If
        End With
    
    Next ws

    Application.ScreenUpdating = True

End Sub
Sub ZoomSheets()

    Application.ScreenUpdating = False

    Dim ws As Worksheet
    Dim checkRng As String: checkRng = "A1:ZZ999"
    Dim picture As Variant
    For Each ws In ThisWorkbook.Worksheets
    
        With ws.Range(checkRng)
            If Not .Find("epic", LookIn:=xlValues) Is Nothing Then
                ws.Activate
                ActiveWindow.Zoom = 90
            ElseIf Not .Find("poggers", LookIn:=xlValues) Is Nothing Then
                ws.Activate
                ActiveWindow.Zoom = 80
            Else
                For Each picture In ws.Pictures
                    If picture.Name Like "*Picture*" Then
                        ws.Activate
                        ActiveWindow.Zoom = 70
                        Exit For
                    End If
                Next
            End If
        End With
    
    Next ws

    Application.ScreenUpdating = True

End Sub
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文