当文件存在冻结时,先结冻再冻结,无冻结时直接冻结。?
简单有用:直接看
全代码:
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")工作表可更改。