excel - 如果系统时间在开始时间到结束时间之间每10分钟自动运行一次宏VBA excel

标签 excel vba

我正在使用 Excel 2013, 如果系统时间在开始时间到结束时间 VBA excel 之间每 10 分钟运行一次,我需要自动运行宏。

VBA Code:
'In Workbook events:
Private Sub Workbook_Open()
    Call Update
End Sub

'In a Module:
Dim RunTimer As Date
Sub Update()
   RunTimer = Now + TimeValue("00:00:20")
   Application.OnTime RunTimer, "Update"

  'Do Something Your Code
   MsgBox "Data Update.", vbInformation
End Sub

例如:

  1. Excel 打开
  2. 开始时间为上午 9:30
  3. 结束时间为下午 5:00
  4. 每 10 分钟显示一次“msgbox”

请帮助我,提前致谢

如果系统时间在开始时间到结束时间之间每 10 分钟 VBA excel 运行一次,我需要自动宏运行

最佳答案

让您的代码像以前一样随时运行。您当前的代码每 20 秒发出一次调用,因为您每 10m 才需要一次调用,因此将分配更改为 RunTimerTimeValue("00:10:00") .

现在代码将运行 10 分钟。您只需检查当前时间是否在 9:30 到 17:00 之间。如果是,请执行您想要的任何操作。

Sub Update()
    Const StartTime = "09:30"
    Const EndTime = "17:00"
    
    Dim RunTimer As Date
    RunTimer = Now + TimeValue("00:10:00")
    Application.OnTime RunTimer, "Update"

    If Time >= CDate(StartTime) And Time <= CDate(EndTime) Then
        'Do whatever you need to...
        MsgBox "Data Update.", vbInformation
    End If
End Sub

关于excel - 如果系统时间在开始时间到结束时间之间每10分钟自动运行一次宏VBA excel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75687101/

相关文章:

excel - 将我的 Excel 数据集中的所有连字符更改为点

javascript - 使用 VBA 在网络上使用下载按钮

vba - 如果使用 VBA 填充表格,标题行不会自动在后续页面上重复

vba - 如何使用宏查找 MS Word 文档中的所有首字母缩略词?

ms-access - 通过弹出密码框绕过换档

mysql - 只显示 1 个结果的查询

c# - 编码的 UI 单元测试 Excel 连接字符串不起作用

excel - 从 Excel VBA 浏览文件

xml - Excel VBA 从 XML 获取特定节点

sql - 将 SQL 查询结果导出到 CSV