vba freeze panes without sheet activating

1.8k Views Asked by At

Is it possible to freeze top row without activating/selecting the cells/sheets? I just want to specify the Workbook, Sheet and what to freeze on it.

Sheets(1).Activate
With ActiveWindow
        .SplitColumn = 0
        .SplitRow = 1
        .FreezePanes = True
End With
1

There are 1 best solutions below

0
VBasic2008 On

Freeze Window 'Without Activating'

  • Of course, it's not possible but here is the automation I mentioned in the comments.
  • This might help, although I cannot see the purpose of it.
  • In the ThisWorkbook module paste the following code.
  • Adjust the sheet names, codenames, or indexes.
Option Explicit


Private Sub Workbook_SheetActivate(ByVal Sh As Object)
    If Sh.Name = "Sheet2" Then Freeze1
End Sub


Private Sub Workbook_Open()
    If ActiveSheet.Name = "Sheet2" Then Freeze1
End Sub


Private Sub Freeze1()
    On Error GoTo ClearError
    
    Application.EnableEvents = False
    
    Me.Sheets(1).Activate
    With ActiveWindow
        .SplitColumn = 0
        .SplitRow = 1
        .FreezePanes = True
    End With
    Me.Worksheets("Sheet2").Activate
    
SafeExit:
    If Not Application.EnableEvents Then Application.EnableEvents = True
    Exit Sub
ClearError:
    Debug.Print "Run-time error '" & Err.Number & "': " & Err.Description
    Resume SafeExit
End Sub