2015-06-07 117 views
2

問題: 當我使用excel vba爲單個工作簿打開多個excel窗口時,當我嘗試打開名稱管理器時,excel凍結。當我在2007版的Excel中使用相同的代碼時,不會發生此行爲。Excel 2013 VBA爲單個工作簿打開多個窗口

我沒有打開任何加載項,如果我爲同一個工作簿手動打開多個窗口,則不會發生此問題。我還修復了2013版的辦公室,以確保它沒有損壞。

我認爲我的代碼有問題導致問題。我沒有看到問題是什麼,希望這裏有人能夠告訴我,我的代碼是否有問題。代碼運行沒有問題,問題出現在打開窗口後,我嘗試打開名稱管理器。

我通過調試器運行代碼(逐步完成)並完成了沒有任何錯誤。我還確保沒有可能導致問題的外部鏈接引用。

環境:

  • 的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 

回答

1

我做了一些測試,發現如果我修改在第三個case語句中窗口的寬度爲225,excel不再凍結。我向微軟提出了一個案例,他們同意這是Excel 2013中的一個錯誤。他們目前正在研究這個問題。

它出現excel 2013在這種情況下無法處理200或更低的窗口寬度。

相關問題