博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
VBA精彩代码分享-2
阅读量:5282 次
发布时间:2019-06-14

本文共 1186 字,大约阅读时间需要 3 分钟。

VBA开发中经常需要提示消息框,如果不关闭程序就会暂时中断,这里分享下VBA如何实现消息框的自动关闭,总共有三种方法:

第一种方法

Public Declare Function MsgBoxTimeOut Lib "user32" Alias "MessageBoxTimeoutA" (ByVal hwnd As Long, ByVal lpText As String, ByVal lpCaption As String, ByVal wType As Long, ByVal wlange As Long, ByVal dwTimeout As Long) As LongPublic Sub 录入对话() '过程,"弹出对话","对话框标题",图标类型,默认参数,N秒后自动关闭MsgBoxTimeOut 0, "录入完毕!!", "提示", 64, 0, 1500End Sub

第二种方法

Sub pop()Dim wsh As ObjectSet wsh = CreateObject("wscript.shell")wsh.popup "请您输入有效数字", 1, "注意", vbInformation'CreateObject ("wscript.shell").popup "请您输入有效数字", 1, "注意", vbInformationEnd Sub

第三种方法

Public Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal nidevent As Long, ByVal uelaspe As Long, ByVal lptimerfunc As Long) As LongPublic Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal nidevent As Long) As LongDim TID As LongConst sec = 3Sub closetest(ByVal hwnd As Long, ByVal umsg As Long, ByVal idevent As Long, ByVal systime As Long)Application.SendKeys "~", TrueKillTimer 0, TIDEnd SubSub 三秒钟后关闭()TID = SetTimer(0, 0, sec * 1000, AddressOf closetest)MsgBox sec & "秒钟自动关闭窗口", 65, "提示"End Sub

 

转载于:https://www.cnblogs.com/JTCLASSROOM/p/10880998.html

你可能感兴趣的文章
《The Benefit of Group Sparsity》
查看>>
浅析PHP反序列化漏洞之PHP常见魔术方法(一)
查看>>
【SICP练习】14 练习1.20
查看>>
tomcat性能优化Server——Connector
查看>>
git生成key
查看>>
java之aop
查看>>
Python-类的继承与派生
查看>>
第6次课Windows API绘图函数
查看>>
hdu 4507 吉哥系列故事——恨7不成妻(数位DP,5级)
查看>>
Xcode: 给项目添加framework
查看>>
浅谈字体小图标font awesome,iconfont,svg各自优缺点
查看>>
Java 8 – TemporalAdjusters examples
查看>>
Spring自定义标签的实现
查看>>
P2860 [USACO06JAN]冗余路径Redundant Paths tarjan
查看>>
PAT1007
查看>>
Yii2 使用a标签发送post请求
查看>>
Python基础
查看>>
DIV+ul+LI实现表格效果以及div带滑动条
查看>>
css控制input标签
查看>>
Android--将图片存放到我们本地
查看>>