首页 > 解决方案 > 在保护工作表中允许插入行和列,但仍然弹出警告消息,如何阻止?

问题描述

我有以下代码来保护我的工作表

Sub Lock_RESULT_SHEET ()

Application.ScreenUpdating = False

Sheets("RESULT").Select
ActiveSheet.Unprotect Password:="ABCD"
ActiveSheet.Cells.Locked = False



ActiveSheet.Range("A3:E5000").Locked = True


ActiveSheet.Protect Password:="ABCD", Contents:=True, DrawingObjects:=False, UserInterfaceOnly:=True, _
    AllowFormattingCells:=True, AllowFiltering:=True, AllowSorting:=True,AllowInsertingRows:=True,AllowInsertingColumns:=True

END SUB

## 有什么问题?## 在代码中,我确实允许插入行和列,但是当我插入它时,弹出警告显示“您尝试更改的单元格或图表在受保护的工作表上”VBA 专家,请帮助我。先感谢您。

标签: excelvbaexcel-formula

解决方案


正如@Jeeped 之前提到的,这应该是您需要添加的全部内容。确保您标记的Application.X = False内容最终设置回= True

Sub Lock_RESULT_SHEET ()

Application.ScreenUpdating = False
Application.DisplayAlerts = False

Sheets("RESULT").Select
ActiveSheet.Unprotect Password:="ABCD"
ActiveSheet.Cells.Locked = False



ActiveSheet.Range("A3:E5000").Locked = True


ActiveSheet.Protect Password:="ABCD", Contents:=True, DrawingObjects:=False, UserInterfaceOnly:=True, _
    AllowFormattingCells:=True, AllowFiltering:=True, AllowSorting:=True,AllowInsertingRows:=True,AllowInsertingColumns:=True

Application.ScreenUpdating = True
Application.DisplayAlerts = True

END SUB

推荐阅读