用取消选项延迟auto_openmacros

我目前正在开发一个macros,我将最终使用每天从networking导入数据,这将打开Excel文件时激活。 数据只在一天中的某个时间之后才有意义,我将在这段时间之后使用任务计划程序自动打开文件。

唯一的问题是,当我手动打开文件时,我不希望macros运行,因此我想知道是否可以在macros上放置一个延时计时器,并增加了停止执行macros的function在这段时期。 或者如果有任何其他可能的解决scheme来解决这个问题。

欢呼声

打开工作簿时可以有一个msgbox。

  • 如果您单击取消,代码将不会运行。
  • 如果您单击确定,代码将运行。
  • 如果5秒内没有做任何事情(任务计划程序),代码将运行。

Private Sub Workbook_Open() Dim msg As String, runcode As Long msg = "Click cancel to abort or the code will execute in 5 seconds!" runcode = CreateObject("Wscript.Shell").Popup(msg, 5, "What to do:", vbOKCancel) If runcode = 2 Then End 'call import data macro End Sub