Although I am a front-end developer but recently got to work on something exciting. It took me a while to figure things out and merge different variation of codes to create a working code.
Hope it helps developers like me out there.... :)
Lets start with very common requirement :
-> Freezing of Panes in excel.
I had to download an excel file while creating it on the fly which was required to have first column and first row freezed. Even after multiple tries, I couldn't freeze it using given framework, So I switched to VBScript.
For it, we can create a simple sub and write :
Hope it helps developers like me out there.... :)
Lets start with very common requirement :
-> Freezing of Panes in excel.
I had to download an excel file while creating it on the fly which was required to have first column and first row freezed. Even after multiple tries, I couldn't freeze it using given framework, So I switched to VBScript.
For it, we can create a simple sub and write :
Sub LockMyPane()
Application.ScreenUpdating = False
With ActiveWindow
.SplitColumn = 1: .SplitRow = 1
.FreezePanes = True
End With
Application.ScreenUpdating = True
End Sub
Application.ScreenUpdating is required to toggle so that we don't visualize code running in background.
You can use SplitColumn to split as my columns as required, and same goes for SplitRow for spliting number of rows.
And if you want it for all sheets in your workbook you can use SheetActivate event:
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
LockMyPane
End Sub
And if you want it for all sheets in your workbook you can use SheetActivate event:
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
LockMyPane
End Sub
No comments:
Post a Comment