【问题标题】:Excel 2013 VBA opening multiple windows for a single workbookExcel 2013 VBA 为单个工作簿打开多个窗口
【发布时间】:2015-06-07 20:42:28
【问题描述】:

问题: 当我使用 excel vba 为单个工作簿打开多个 excel 窗口时,当我尝试打开名称管理器时,excel 冻结。当我在 2007 版本的 excel 中使用相同的代码时,不会发生这种行为。

我没有打开任何加载项,如果我为同一个工作簿手动打开多个窗口,则不会发生此问题。我还对 2013 版的 office 进行了修复,以确保它没有损坏。

我认为导致问题的代码有问题。我没有看到问题是什么,希望这里的人能够告诉我我的代码是否有问题。代码运行没有问题,窗口打开后出现问题,我尝试打开名称管理器。

我通过调试器运行了代码(单步执行),它完成且没有任何错误。我还确保没有可能导致问题的外部链接引用。

环境:

  • Windows 7
  • Microsoft Office 365(2013 版)

代码:

Option Explicit
Global glbWkBkName As String
'---------------------------------------------------------------------------------------
' Procedure : InitWindows
' Author    : Ron
' Date      : 6/7/2015
' Called By : Workbook_Open
' Purpose   : Sets up 3 windows upon entering the workbook. Provides a view of 3 sheets
'             used while entering data. The middle sheet is where data entry is performed,
'             the left sheet provides reference information on the data being entered,
'             and the right sheet provides summary information about the data entered.
'---------------------------------------------------------------------------------------
'
Sub InitWindows()
    Dim wnWin As Window

    On Error GoTo InitWindows_Error

    glbWkBkName = ThisWorkbook.Name

    Application.ScreenUpdating = False

    'Get rid of all open windows to start at 1.
    'Easier than determining which windows are open and processing them.

    Do Until Windows.Count = 1
        Windows(Windows.Count).Close
    Loop

    'Create 2 more for a total of 3 windows.
    ActiveWindow.NewWindow
    ActiveWindow.NewWindow

    For Each wnWin In Windows
        Select Case wnWin.WindowNumber
                'Left window: SkillTreeLayout
            Case Is = 1
                wnWin.Activate
                Sheets("SkillTreeLayout").Select
                With wnWin
                    .WindowState = xlNormal
                    .Top = 6
                    .Left = 6
                    .Width = 514
                    .Height = 627
                    .DisplayGridlines = False
                End With
            Case Is = 2
                'Middle window: DataEnry
                wnWin.Activate
                Sheets("DataEntry").Select
                With wnWin
                    .WindowState = xlNormal
                    .Top = 6
                    .Left = 530
                    .Width = 698
                    .Height = 627
                    .DisplayGridlines = False
                End With
            Case Is = 3
                'Right window: DataEntrySummary
                wnWin.Activate
                Sheets("DataEntrySummary").Select
                With wnWin
                    .WindowState = xlNormal
                    .Top = 6
                    .Left = 1230
                    .Width = 200
                    .Height = 627
                    .DisplayGridlines = False
                End With
        End Select
    Next wnWin

    Debug.Assert glbWkBkName <> ""
    Set wnWin = Windows(glbWkBkName & ":2")

    Windows(glbWkBkName & ":2").Activate

    'Debug.Print glbWkBkName & ":2"
    'ClrSkillTreeCharData
ExitProcedure:
    On Error Resume Next
    Set wnWin = Nothing
    Application.ScreenUpdating = True
    Exit Sub

InitWindows_Error:
    Call UnexpectedError(Err.Number, Err.Description, Err.Source, _
    Err.HelpFile, Erl, "InitWindows")
    Resume ExitProcedure
End Sub

【问题讨论】:

    标签: vba excel


    【解决方案1】:

    我做了一些额外的测试,发现如果我将第三个case语句中的窗口宽度修改为225,excel不再冻结。我向 Microsoft 提出了一个案例,他们同意这是 Excel 2013 中的一个错误。他们目前正在解决这个问题。

    在这种情况下,excel 2013 似乎无法处理 200 或更低的窗口宽度。

    【讨论】:

      猜你喜欢
      • 2015-09-10
      • 2023-04-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多