如何实现打开工作簿就自动运行VBA代码?
时间:2022-10-12 06:23:14
如下图所示的工作表,我希望在打开该工作簿时,用户能看到一条关于该工作簿用途的提示消息,如何编写VBA代码?
答:有两种实现方法。
第一种,使用Workbook_Open事件。代码如下:
Private Sub Workbook_Open()
MsgBox “本工作簿用于记录个人私密信息,外人请勿观看!”
End Sub
注意,该代码一定要在ThisWorkbook模块中,如下图所示。
第二种,使用Auto_Open()事件。在VBE中,插入一个标准模块,输入下面的代码:
Sub Auto_Open()
MsgBox “本工作簿用于记录个人私密信息,外人请勿观看!”
End Sub
注意,该代码在标准模块中,且过程名为Auto_Open,如下图所示。
用途
使用该方法,可以在打开工作簿时:
1.给用户提示,无论是警告提示还是操作提示。
2.自动加载自定义的内容,包括定制的界面。
3.加密工作簿,只有用户输入正确的密码,才能打开工作簿。
标签:excel使用技巧,excel入门教程,excel表格的公式,Excel教程
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
神舟战神Z7T怎么重装系统?重装神舟战神Z7T系统的方法
2023-06-04 15:16:43
![](https://img.aspxhome.com/file/2023/8/46408_0s.png)
excel如何快速删除掉所有的文本框?
2022-01-31 16:44:18
![](https://img.aspxhome.com/file/2023/2/40812_0s.jpg)
word表格如何自动排序生成序号
2022-03-15 13:28:53
![](https://img.aspxhome.com/file/2023/8/35068_0s.png)
如何将一个文字(Word)档案转换成资料图片( JPEG)格式
2023-03-15 10:04:39
![](https://img.aspxhome.com/file/2023/5/23845_0s.jpg)
word页面背景纹理怎么设置
2023-03-27 05:07:49
![](https://img.aspxhome.com/file/2023/3/35933_0s.png)
Excel2016表头制作技巧
2022-03-10 18:22:56
![](https://img.aspxhome.com/file/2023/7/36287_0s.jpg)
Word 2010文档内容控件的使用方法
2023-05-05 07:40:56
![](https://img.aspxhome.com/file/2023/7/34077_0s.jpg)
word2013把文字倒过来显示的操作步骤
2022-04-29 20:59:02
![](https://img.aspxhome.com/file/2023/3/29303_0s.jpg)
WPS文字文档到Office2003中Word打开格式变了怎么办?
2023-12-08 17:32:55
![](https://img.aspxhome.com/file/2023/0/20060_0s.png)
利用word画虚线,画折线图,画曲线图的方法
2023-06-06 07:48:27
![](https://img.aspxhome.com/file/2023/8/24098_0s.jpg)
excel怎么输入绝对引用符号
2023-08-31 18:03:56
![](https://img.aspxhome.com/file/2023/5/a140495_0s.png)
Apple Music 音质怎么样,是无损吗?
2023-11-29 14:48:23
![](https://img.aspxhome.com/file/2023/7/a194927_0s.jpg)
3种方法供你参考 在Word中如何画横线和下划线
2023-05-07 09:35:27
![](https://img.aspxhome.com/file/2023/5/29995_0s.jpg)
如何将日期和时间添加到Word 2010文档?
2023-09-01 22:43:39
![](https://img.aspxhome.com/file/2023/7/23277_0s.jpg)
Win10 1909默认安装盘怎么修改?Win10 1909默认安装盘修改教程
2023-11-10 19:31:20
![](https://img.aspxhome.com/file/2023/0/48770_0s.jpg)
word 斜线表头如何制作 word斜线表头命令的具体位置
2023-11-18 04:25:11
![](https://img.aspxhome.com/file/2023/7/33277_0s.gif)
word中如何制作文字双行合一
2022-05-26 21:48:49
Win10系统连接上网络但是不能上网是什么问题?
2023-07-28 20:13:47
![](https://img.aspxhome.com/file/2023/4/46674_0s.jpg)
EXCEL 2007中如何在折线图中插入标题及横竖坐标名称
2023-02-08 21:35:33
![](https://img.aspxhome.com/file/2023/8/36168_0s.jpg)
用分页符在Word长篇文档中定义多个不同页眉
2022-10-12 21:21:33
![](https://img.aspxhome.com/file/2023/2/21262_0s.jpg)