2015-09-04 61 views

回答

0

我不相信你可以达到你用窗格寻找的效果。当您在数据中滚动浏览时,窗格被设计为将标题行和列保留在屏幕上。

您需要打开第二个窗口,然后调整大小以填充屏幕的左半部分,另一个填充屏幕的右半部分。

尝试以下操作:

Option Explicit 
Sub Demo() 

    ' You may have to experiment to get these values correct for your system. 
    Const BorderHeight As Single = 30! 
    Const BorderWidth As Single = 15! 
    Const WindowLeft As Single = 1! 
    Const WindowTop As Single = 1! 

    Dim WindowHeight As Single 
    Dim WindowWidth As Single 
    Dim WshtNameLeft As String 
    Dim WshtNameRight As String 

    WshtNameLeft = "Sheet1"  ' Rename as required 
    WshtNameRight = "Sheet2"  ' Rename as required 

    ' This demonstrates the macro does not depend on either of 
    ' the target worksheets being active. Delete from final code. 
    Worksheets("Sheet3").Activate 

With ActiveWindow 
    ' Record full size of window 
    WindowHeight = .Height 
    WindowWidth = .Width 
    ' Open a second window 
    .NewWindow 
    .WindowState = xlNormal 
    End With 

    Windows(ActiveWorkbook.Name & ":1").Activate 

    With ActiveWindow 
    ' Size window to half width while allowing for borders. Position on left 
    .Height = WindowHeight - BorderHeight 
    .Left = WindowLeft 
    .Top = WindowTop 
    .Width = (WindowWidth - BorderWidth)/2 
    End With 

    Worksheets(WshtNameLeft).Select 

    Windows(ActiveWorkbook.Name & ":2").Activate 

    With ActiveWindow 
    ' Size window to half width while allowing for borders. Position on right 
    .Height = WindowHeight - BorderHeight 
    .Top = WindowTop 
    .Width = (WindowWidth - BorderWidth)/2 
    ' "+ 1" is to ensure windows do not overlap 
    .Left = WindowLeft + (WindowWidth - BorderWidth)/2 + 1 
    End With 

    Worksheets(WshtNameRight).Select 

End Sub