Excel 2013 VBA opening multiple windows for a single workbook

2.7k Views Asked by At

Problem: When I use excel vba to open multiple excel windows for a single workbook, excel freezes when I try to open the name manager. This behavior does not happen when I use the same code in the 2007 version of excel.

I don't have any add-ins turned on, and this problem doesn't happen if I open multiple windows manually for the same workbook. I also ran a repair of the 2013 version of office to ensure it was not corrupted.

I assume there is something wrong with my code which is causing the problem. I am not seeing what the issue is, and was hoping someone here might be able to tell me if there is a problem with my code. The code runs with no issues, the problem occurs after the windows are open and I try to open the name manager.

I ran the code through the debugger (stepped through it) and it completed without any errors. I also made sure that there were no external link references that might be causing issues.

Environment:

  • Windows 7
  • Microsoft Office 365 (2013 version)

Code:

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
1

There are 1 best solutions below

0
On BEST ANSWER

I did some additional testing and found that if I modify the width of the window in the third case statement to 225, excel no longer freezes. I opened a case with Microsoft and they agreed that this was a bug in Excel 2013. They are currently working on this.

It appears excel 2013 is unable to handle window widths of 200 or lower in this scenario.