vba 每天在同一时间启动一个宏

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28495769/
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-12 06:12:50  来源:igfitidea点击:

start a macro every day on the same time

excel-vbavbaexcel

提问by Freek v. wely

I have a macro and i will run that macro automatically, always on the same time on Monday to Friday. I have already a macro but that runs one time after opening the file. How to get repeat every day until saterday and sunday?

我有一个宏,我将自动运行该宏,始终在周一至周五的同一时间运行。我已经有一个宏,但在打开文件后运行一次。如何每天重复直到星期六和星期日?

Public Sub Workbook_Open()

Dim dtmStarttijd As Date
dtmStarttijd = TimeSerial(7, 10, 0)
' Is de macro gestart?
MsgBox "De macro voor het automatisch starten van de procedure is gestart."


Application.OnTime dtmStarttijd, "sDeUitTeVoerenMacro"


End Sub

Kind regards Freek

亲切的问候弗里克

回答by K?τ?

To start a macro at given time and on weekdays should this work:

在给定的时间和工作日启动宏应该这样工作:

Sub test()
If Weekday(Now, vbMonday) < 6 Then 'check if weekday is < 6, starting by Monday with 1 (Sat = 6, Sun = 7)
Application.OnTime TimeValue("00:01:10"), "YourSub"
End If
End Sub

Change TimeValue("00:01:10")when the macro should start

更改TimeValue("00:01:10")宏的启动时间

Change "YourSub"with your sub, e.g. your sub is named Sub timestart()put in "timestart"(without () but "" are needed!)

更改"YourSub"您的子程序,例如您的子程序名为Sub timestart()put in "timestart"(没有 () 但需要 ""!)

Excel has to be started for working

必须启动 Excel 才能工作

回答by Dan Donoghue

I set mine as scheduled tasks in windows and make it run in a safe mode copy of Excel with a quit at the end of the macro.

我将我的任务设置为 Windows 中的计划任务,并使其在 Excel 的安全模式副本中运行,并在宏结束时退出。

Make sure you do workbook.saved = true before quitting to suppress the prompt.

确保在退出之前执行 workbook.saved = true 以取消提示。