简体   繁体   English

使用Workbook_BeforeClose终止Application.ontime

[英]Killing Application.ontime with Workbook_BeforeClose

I looked through every topic I've found in here, but couldn't figure what is wrong with the below. 我浏览了我在这里找到的每个主题,但无法确定下面的问题。

I am using Application.OnTime to run a Module every minutes. 我正在使用Application.OnTime每分钟运行一个模块。 The problem is, when I close the worksheet, Excel reopens the sheet the next time the Macro should run. 问题是,当我关闭工作表时,Excel在下次应运行宏时重新打开工作表。

I have attempted to use the following fix, to no avail. 我试图使用以下修复程序,但无济于事。

Option Explicit
Dim dTime As Date

Public Function AutoRun2()
dTime = Now + TimeValue("00:01:00")
Application.OnTime dTime, "AutoClear"
End Function

Sub StopAutoRun2()
Application.OnTime dTime, "AutoRun2", , False
End Sub

and I have the following in ThisWorkbook: 并且在ThisWorkbook中有以下内容:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Call StopAutoRun
Call StopAutoRun2
End Sub

What am I doing wrong here? 我在这里做错了什么?

在stop子目录中将"AutoRun2"更改为"AutoClear" ,因为这是您要停止使用False参数调度的实际宏。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM