简体   繁体   English

Workbook_Open事件更改其他工作簿

[英]Workbook_Open event changes other workbooks

I have the code below in Workbook module: 我在工作簿模块中有以下代码:

Private Sub Workbook_Open()
Application.ExecuteExcel4Macro "SHOW.TOOLBAR(""Ribbon"",False)"
    Application.DisplayFormulaBar = False
    Application.DisplayStatusBar = Not Application.DisplayStatusBar
    ActiveWindow.DisplayWorkbookTabs = False
    ActiveWindow.DisplayHeadings = False
        Application.WindowState = xlMaximized
    ActiveSheet.UsedRange.Select
    ActiveWindow.Zoom = True
    Range("A1").Select
End Sub

But when I open the workbook in question, the settings in the code are also applied to all other workbooks that are opened. 但是,当我打开有问题的工作簿时,代码中的设置也将应用于所有其他打开的工作簿。 How could I limit the settings in the code to apply only to the workbook in question? 我如何限制代码中的设置以仅应用于有问题的工作簿? Best Regards 最好的祝福

EDIT: This solution does not work for me either: 编辑:此解决方案对我也不起作用:

Private Sub Workbook_Open()
With Me
    Application.WindowState = xlMaximized
    ActiveSheet.UsedRange.Select
    ActiveWindow.Zoom = True
    Range("A1").Select
    Application.ExecuteExcel4Macro "SHOW.TOOLBAR(""Ribbon"",False)"
    Application.DisplayFormulaBar = False
    Application.DisplayStatusBar = Not Application.DisplayStatusBar
    ActiveWindow.DisplayWorkbookTabs = False
    ActiveWindow.DisplayHeadings = False
    End With

End Sub

try this, add a With me in the line after the Private Sub Workbook_Open() like this 试试这个,像这样在Private Sub Workbook_Open()之后的行中添加一个With me

Private Sub Workbook_Open()
with me
'all the rest of the code
end with
end sub

it worked here 它在这里工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM