0

我试图每天早上 9 点运行一个宏。我正在尝试使用 OnTime 应用程序并测试了宏以在特定时间启动,但它不能自动工作。我必须手动运行宏才能弹出消息框。有什么建议吗?

Sub FinancialAlert()

    Application.OnTime TimeValue("15:33:00"), "Summary of Covered Companies"


    Dim i As Long
    i = 5

    While Workbooks("Montreal Issuers.xlsm").Sheets("Summary of Covered Companies").Cells(i, 5) <> ""

    With Workbooks("Montreal Issuers.xlsm")

        If .Sheets("Summary of Covered Companies").Cells(i, 5).Value = 1 Then

            MsgBox Workbooks("Montreal Issuers.xlsm").Sheets("Summary of Covered Companies").Cells(i, 3).Value & " is issuing their next financial statement tomorrow (" & _
            Format(Workbooks("Montreal Issuers.xlsm").Sheets("Summary of Covered Companies").Cells(i, 4).Value, "[$-409]mmmm d, yyyy;@") & ")."


        End If

        If .Sheets("Summary of Covered Companies").Cells(i, 5).Value = 0 Then

            MsgBox Workbooks("Montreal Issuers.xlsm").Sheets("Summary of Covered Companies").Cells(i, 3).Value & " is issuing their next financial statement today (" & _
            Format(Workbooks("Montreal Issuers.xlsm").Sheets("Summary of Covered Companies").Cells(i, 4).Value, "[$-409]mmmm d, yyyy;@") & ")."


        End If


    End With

    i = i + 1

    Wend

End Sub
4

2 回答 2

2

这可以做到,但是,您需要ThisWorkbookWorkbook_Open例程中的模块中运行on time:

Private Sub Workbook_Open()
    Application.OnTime TimeValue("15:33:00"), "Summary of Covered Companies"
End Sub

宏不会独立运行。打开工作簿时,此命令将安排它。如果该命令仅在宏本身中调用,Excel 将永远不会知道,直到有东西激活它。

于 2016-06-17T20:59:34.493 回答
1

您可以安排窗口以使用任务计划程序打开文件。然后让宏在 Workbook Open 上运行并关闭文件。

我多年来一直在使用的另一个想法是安排 Gmail 在每天的给定时间向特定帐户发送一封电子邮件,主题中包含一个代码字。然后,如果电子邮件带有该代码字,我会让 Outlook 运行一个宏。这使我能够通过停止发送电子邮件来远程停止宏。它完美无缺。

于 2016-06-17T21:35:22.823 回答