excel禁止插入(添加)工作表的几种不同的VBA语句写法
时间:2022-03-17 18:42:58
有时候工作需要,禁止用户在现有的工作薄中插入添加工作表。用基础操作无法实现禁止插入(添加)工作表,可以使用VBA代码来完成。
禁止插入(添加)工作表的方法一:
按下ALT+F11,打开VBE编辑器,在ThisWorkbook中添加以下代码:
Private Sub Workbook_NewSheet(ByVal Sh As Object)
Application.DisplayAlerts = False
ActiveSheet.Delete
Application.DisplayAlerts = True
End Sub
下面是用VBA禁止插入(添加)工作表的一个截图:
禁止插入(添加)工作表的方法二:
将方法一的代码改为下面的:
Private Sub Workbook_NewSheet(ByVal Sh As Object)
'关闭屏幕的刷新
Application.ScreenUpdating = False
'关闭删除工作表时显示的提示对话框
Application.DisplayAlerts = False
Sh.Delete
'打开屏幕刷新
Application.ScreenUpdating = True
End Sub
这样也可以禁止在一个工作簿中添加插入工作表。这段代码严格的是只是将新增加的工作表删除。
禁止插入(添加)工作表的方法三:
代码人性化直观一些,用消息框提示:
Private Sub Workbook_NewSheet(ByVal Sh As Object)
MsgBox "你不能插入工作表"
Application.DisplayAlerts = False
ActiveSheet.Delete
Application.DisplayAlerts = True
End Sub
excel禁止插入(添加)工作表的几种不同的VBA语句写法的下载地址:
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
excel表格怎样固定表头
word文档让标题避免排在一页的底部?
![](https://img.aspxhome.com/file/2023/7/25417_0s.jpg)
word2003怎么打开纸张帮助信息窗口?
![](https://img.aspxhome.com/file/2023/3/30623_0s.jpg)
excel2003运用公式进行计算的方法
在excel中制表格怎样把隐藏的网格显示出来
![](https://img.aspxhome.com/file/2023/6/36596_0s.png)
Excel中图表制作的基本方法
Word怎么输入Z中间加一横
![](https://img.aspxhome.com/file/2023/3/31693_0s.png)
如何在Word2010文档中创建构建基块
![](https://img.aspxhome.com/file/2023/2/29622_0s.jpg)
如何使用Word分隔符 轻松打印超宽图片
![](https://img.aspxhome.com/file/2023/1/29751_0s.jpg)
使用向导将数据从文本文件导入Excel中
Win10电脑怎么启用磁盘写入缓存?Win10电脑启用磁盘写入缓存的方法
![](https://img.aspxhome.com/file/2023/9/51999_0s.jpg)
Word文档怎么打特殊符号?Word文档特殊符号输入方法教学
![](https://img.aspxhome.com/file/2023/2/31112_0s.png)
Win10如何清除win32 trojan病毒?win32 trojan病毒清除教程
![](https://img.aspxhome.com/file/2023/9/52599_0s.png)
Word如何快速添加下划线
![](https://img.aspxhome.com/file/2023/8/33458_0s.gif)
wps怎么设置段落间距如何批量调整段间距
![](https://img.aspxhome.com/file/2023/6/53486_0s.jpg)
正版win10系统安装教程_正版win10系统安装图文分享
![](https://img.aspxhome.com/file/2023/7/47697_0s.jpg)
Word2007图像处理有哪些功能 Word2007图像处理功能介绍
![](https://img.aspxhome.com/file/2023/1/24631_0s.jpg)
Excel IMEXP 函数 使用实例教程
![](https://img.aspxhome.com/file/2023/5/a162495_0s.png)
excel表格怎么导入txt格式文件? txt文档到导入excel的技巧
![](https://img.aspxhome.com/file/2023/1/39831_0s.jpg)