I'm using Excel 2010 to for some automation.
In short, I create a new workbook with this method:
With CreateObject("Excel.Application")
Set NewBook = .Workbooks.Add
.Visible = True
End With
With NewBook
Set WS = NewBook.Sheets("Sheet1")
End With
And now I would like to create a freeze pane.
I've tried using select and ActiveWindow as on this page:
WS.Range("F4").Select
ActiveWindow.FreezePanes = True
Somehow when editing different files, .select method always selects the original file instead of the added book.
I then looked at this page and tried:
NewBook.activate
With ActiveWindow
If .FreezePanes Then .FreezePanes = False
.SplitColumn = 5
.SplitRow = 4
.FreezePanes = True
End With
No use, freeze pane is created on the original file.
Nor does the following work:
With NewBook
If .FreezePanes Then .FreezePanes = False
.SplitColumn = 5
.SplitRow = 4
.FreezePanes = True
End With
Not sure if my .activate method is wrong, or ActiveWindow is wrong, or maybe .select is wrong. Lots of thanks anyone could help.