Hey all
I was hoping someone could elaborate on the behavior of the FreezePanes property -- specifically, what might cause it to fail or produce undesired results.
I have a worksheet, I use the Application.Goto method to select a range at which to freeze (rFreezePoint), then set FreezePanes, then restore the previous selection using Application.PreviousSelection. It seems like the FreezePanes method works correctly only if rFreezePoint is visible on the screen, so I left ScreenUpdating enabled. Beyond this, however, it seems to be behaving oddly. Sometimes it produces the expected results, other times it freezes along the entire column. Not sure why.
Code:
Here's a sample immediate window output to see whats going on:
I was hoping someone could elaborate on the behavior of the FreezePanes property -- specifically, what might cause it to fail or produce undesired results.
I have a worksheet, I use the Application.Goto method to select a range at which to freeze (rFreezePoint), then set FreezePanes, then restore the previous selection using Application.PreviousSelection. It seems like the FreezePanes method works correctly only if rFreezePoint is visible on the screen, so I left ScreenUpdating enabled. Beyond this, however, it seems to be behaving oddly. Sometimes it produces the expected results, other times it freezes along the entire column. Not sure why.
Code:
Code:
Sub FreezePanes(Optional oFreeze As Shape, Optional Source As Worksheet, Optional rFreezePoint As Range)
'defs
On Error GoTo errFatal
fn "FreezePanes"
If Source Is Nothing Then Set Source = ActiveSheet
If oFreeze Is Nothing Then Set oFreeze = Source.Shapes("optFreezePanes")
ToggleEvents False, , True
'set freeze point
If rFreezePoint Is Nothing Then
On Error Resume Next
Set rFreezePoint = Strip(Source.Range("Material.Cost.Unit")).Cells(1, 1) 'template, longform
Set rFreezePoint = Strip(Source.Range("Sheet.Name")).Cells(1, 1).EntireRow 'overview, summary
On Error GoTo errFatal
End If
'freeze & restore prev selection
Application.Goto rFreezePoint 'ico freezing on inactive sheet
ActiveWindow.FreezePanes = oFreeze.OLEFormat.Object.Value = 1
dp "Freezing Panes at [" & rFreezePoint.Address & "]"
Application.Goto Application.PreviousSelections(1)
GoTo quit
errFatal:
dp "!! Error: Unhandled. Terminating"
ActiveWindow.FreezePanes = False
GoTo quit
quit:
ToggleEvents True
fn "FreezePanes", True
End Sub
Here's a sample immediate window output to see whats going on:
Code:
iIndentLevel=3
iIndent=0
bPrintLog=True
Call FreezePanes(Sheet1.Shapes("optFreezePanes"),Sheet1)
## Begin fn_FreezePanes.
$$ Environment Variables: %EnableEvents% = False, %ScreenUpdating% = True, %Calculation% = xlCalculationManual.
Freezing Panes at [$H$14].
$$ Environment Variables: %EnableEvents% = True, %ScreenUpdating% = True, %Calculation% = xlCalculationAutomatic.
## End fn_FreezePanes.