热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

excelvba冻结窗格没有选择-excelvbafreezepanewithoutselect

IhaveaVBAscriptinExcelthatfreezesthepanesofanExcelworksheet,butImcurioustoseeif

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 which freezes rows 1 through 7:

我在Excel中有一个VBA脚本冻结了Excel工作表的窗格,但我很想知道如果没有先选择一个范围,这是否可行。现在通过代码冻结第1行到第7行:

ActiveSheet.Range("A8").Select
ActiveWindow.FreezePanes = True

Any suggestions?

有什么建议么?

2 个解决方案

#1


22  

Record yourself using the View ► Freeze Panes ► Freeze Top Row command and this is what you get for .FreezePanes.

使用视图►冻结窗格►冻结顶行命令记录自己,这就是.FreezePanes的功能。

With ActiveWindow
    If .FreezePanes Then .FreezePanes = False
    .SplitColumn = 0
    .SplitRow = 1
    .FreezePanes = True
End With

So modifying the .SplitColumn and/or .SplitRow properties should do it for you regardless on what the ActiveCell property is.

因此,无论ActiveCell属性是什么,修改.SplitColumn和/或.SplitRow属性都应该为您完成。

#2


0  

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:

我知道这是旧的,但我遇到了这个可能有用的信息......正如ChrisB所说,SplitColumn / SplitRow值代表当前可见窗口的分割BUT上方/左边的最后一个单元格。所以,如果您碰巧有这样的代码:

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.

分割将在行110和111之间而不是10和11之间。


推荐阅读
author-avatar
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有