如何每 30 分钟自动执行一次 vba 宏?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3331065/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 11:55:56  来源:igfitidea点击:

how to execute a vba macro every 30 minutes automatically?

javaexcel-vbavbaexcel

提问by daria

I'm working on a project to send alert notifications to a mailing list. I've an excel file with a vba macro that permit its updating from a datatbase. I need to execute the macro in the file automatically every 30 minutes without having to open the file. i've been told to write this macro in a separate program, but i don't know how to do it.

我正在开展一个项目,将警报通知发送到邮件列表。我有一个带有 vba 宏的 excel 文件,它允许从数据库更新。我需要每 30 分钟自动执行一次文件中的宏,而不必打开文件。有人告诉我在一个单独的程序中编写这个宏,但我不知道该怎么做。

回答by Vincent McNabb

Excel VBA DOM has a nice feature called Application.OnTime. This can schedule a macro to run at any time. To run a Macro every 15 min, just schedule for 15 min in the future on application startup, and then schedule 15 min in the future everytime the macro runs.

Excel VBA DOM 有一个很好的功能,称为Application.OnTime. 这可以安排宏随时运行。要每 15 分钟运行一次宏,只需在应用程序启动时安排 15 分钟,然后在每次运行宏时安排 15 分钟。

From this website: http://www.ozgrid.com/Excel/run-macro-on-time.htm

从这个网站:http: //www.ozgrid.com/Excel/run-macro-on-time.htm

Example:

例子:

Private Sub Workbook_Open()
  Application.OnTime Now + TimeValue("00:15:00"), "MyMacro"
End Sub