Private Sub Workbook_Open()
For Each sht In Worksheets sht.unprotect
sht.Columns("G:I").EntireColumn.Hidden = True sht.protect
Next
End Sub
For Each sht In Worksheets sht.unprotect
sht.Columns("G:I").EntireColumn.Hidden = True sht.protect
Next
End Sub
简单的办法就是设置那两个单元格的属性,下面提供通用性好的代码 Sub hid()
With ActiveSheet
.Unprotect
.Cells.Locked = False
.Columns("A:B").Locked = True
Application.Intersect(.Rows(1), .Columns("A:B")).Locked = False
.Protect
End With
End Sub
With ActiveSheet
.Unprotect
.Cells.Locked = False
.Columns("A:B").Locked = True
Application.Intersect(.Rows(1), .Columns("A:B")).Locked = False
.Protect
End With
End Sub
本文提供了一段使用VBA隐藏Excel工作表中指定列的代码。通过解锁工作表、隐藏特定列并重新保护工作表的方式实现。这段代码适用于需要批量操作Excel表格的工作场景。
1351

被折叠的 条评论
为什么被折叠?



