Search code examples
vbaexcel

Setting FreezePanes Property of the windows class -Excel VBA


I have a huge application for importing and exporting which was written back in the version VBA 9.1 and migrating it to Excel 2013 I'm facing problem during the freezing of first row using this line.

AddWorksheetWithDefaults.Parent.Windows(1).Activate
With AddWorksheetWithDefaults.Parent.Windows(1)
.FreezePanes = False
.FreezePanes = True
End With 

In this case I a''m getting error as Unable to set FreezePanes Property of the windows class

and the AddWorksheetWithDefaults is a method that returns a object(). " I tried following

Try 1

AddWorksheetWithDefaults.Parent.Windows(1).Activate
With AddWorksheetWithDefaults.Parent.Windows(1).Rows("1:1").Select
.FreezePanes = False
.FreezePanes = True
End With

Try 2

AddWorksheetWithDefaults.Parent.Windows(1).Activate
With AddWorksheetWithDefaults.Parent.Windows(1).Rows(1).Select
.FreezePanes = False
.FreezePanes = True
End With

Try 3

AddWorksheetWithDefaults.Parent.Windows(1).Activate
With AddWorksheetWithDefaults.Parent.Windows(1).Rows("1:1")
.FreezePanes = False
.FreezePanes = True
End With

The options I tried gives me error as property or method not found

Help me out.


Solution

  • Try this:

    AddWorksheetWithDefaults.Parent.Windows(1).Activate
    With AddWorksheetWithDefaults.Parent.Windows(1)
        .FreezePanes = False
        .SplitColumn = 0
        .SplitRow = 1
        .FreezePanes = True
    End With