How can I programmatically freeze the top row of an Excel worksheet in Excel 2007 VBA?

前端 未结 6 895
终归单人心
终归单人心 2020-12-06 04:10

I am looking to programmatically freeze the top row of an Excel worksheet from VBA. The end goal is to produce the same effect as the View > Freeze Panes > Free

6条回答
  •  醉梦人生
    2020-12-06 04:31

    Just hit the same problem... For some reason, the freezepanes command just caused crosshairs to appear in the centre of the screen. It turns oout I had switched ScreenUpdating off! Solved with the following code:

    Application.ScreenUpdating = True
    Cells(2, 1).Select
    ActiveWindow.FreezePanes = True
    

    Now it works fine.

提交回复
热议问题