ActiveWindow.FreezePanes behavior

ButtFace

Board Regular
Joined
Oct 16, 2015
Messages
63
Office Version
  1. 2016
Platform
  1. Windows
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:
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.
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Nevermind. Answered my own question. Forgot to enable scrolling for Application.Goto. Derp. :rolleyes:
 
Upvote 0

Forum statistics

Threads
1,223,249
Messages
6,171,031
Members
452,374
Latest member
keccles

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top