用VBA冻结excel文件的sheet1工作簿的第一行

发布时间:2023年12月19日

当文件存在冻结时,先结冻再冻结,无冻结时直接冻结。?

简单有用:直接看

全代码:

Dim targetWorkbook As Workbook
Dim targetWorksheet As Worksheet
Dim filePath As String

filePath = "D:\xin.xlsx" ' フ貊サホェxin.xlsxホトシ?オトハオシハツキセカ

On Error Resume Next
Set targetWorkbook = Workbooks.Open(filePath)
On Error GoTo 0

If Not targetWorkbook Is Nothing Then
Set targetWorksheet = targetWorkbook.Sheets("Sheet1") ' フ貊サホェトソア?、ラ昉トテ﨤ニ
If Not targetWorksheet Is Nothing Then
targetWorksheet.Activate
If targetWorksheet.Application.ActiveWindow.FreezePanes Then
targetWorksheet.Application.ActiveWindow.FreezePanes = False ' ス箋?カウス?
targetWorksheet.Rows("3:" & targetWorksheet.Rows.count).Select
targetWorksheet.Application.ActiveWindow.FreezePanes = False ' ス箋?マヨモミエーク?
targetWorksheet.Rows(2).Select
targetWorksheet.Application.ActiveWindow.FreezePanes = True
Else
targetWorksheet.Rows("3:" & targetWorksheet.Rows.count).Select
targetWorksheet.Application.ActiveWindow.FreezePanes = False ' ス箋?マヨモミエーク?
targetWorksheet.Rows(2).Select
targetWorksheet.Application.ActiveWindow.FreezePanes = True ' カウス盞レカ?ミミ
End If
End If
End If

可直接使用,改换?filePath = "D:\xin.xlsx" 中的路径即可。

Set targetWorksheet = targetWorkbook.Sheets("Sheet1")工作表可更改。

文章来源:https://blog.csdn.net/2301_77630091/article/details/132444652
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。