excel vba freeze pane without select

后端 未结 5 1348
情歌与酒
情歌与酒 2020-11-30 07:39

I have a VBA script in Excel that freezes the panes of an Excel worksheet, but I\'m curious to see if this is possible without first selecting a range. Here\'s by code now

5条回答
  •  南笙
    南笙 (楼主)
    2020-11-30 08:22

    I know this is old but I came across this tidbit that may be useful... as ChrisB stated, the SplitColumn/SplitRow values represent the last cell above/left of the split BUT of the currently visible window. So if you happen to have code like this:

    Application.Goto Worksheets(2).Range("A101"), True
    With ActiveWindow
     .SplitColumn = 0
     .SplitRow = 10
     .FreezePanes = True
    End With
    

    The split will be between rows 110 and 111 instead of 10 and 11.

    edited for clarification and to add more information:
    My point is that the values are offsets of the upper left cell, not an address of a cell. Therefore, ChrisB's Dec 4 '15 at 18:34 comment under the main answer only holds if row 1 is visible in the Activewindow.

    A couple of other points on this:

    1. using Application.goto doesn't necessarily put whichever cell you are trying to go to in the upper left
    2. the cell that is put in the upper left when using .goto can depend on the size of the excel window, the current zoom level, etc (so fairly arbitrary)
    3. it is possible to have the splits placed so that you can not see them or even scroll around in the visible window (if .FreezePanes = true). for example:
    Application.Goto Worksheets(1).Range("A1"), True  
    With ActiveWindow  
     .SplitColumn = 100  
     .SplitRow = 100  
     .FreezePanes = True  
    End With  
    

    CETAB may be dealing with this in their answer.

提交回复
热议问题