当任务计划程序设置为 "Run whether user logged on or not" 时,VBA 失败

VBA fails when Task Scheduler is set to "Run whether user logged on or not"

我有一个 Access VBA 宏,可以生成报告,将其保存为 .pdf 格式,然后使用 CDO 通过电子邮件发送。如果我手动 运行 或者如果我使用安全选项 "Run only when user is logged on" 在 Task Scheduler 上将它设置为 运行,一切都正常。但是,如果我将选项设置为 "Run whether user is logged on or not"(即使使用选项 "Run with highest privileges"),程序会在第二行崩溃:

strFileFullPath = CurrentProject.Path & "\Test Report.pdf" DoCmd.OutputTo acOutputReport, strReportName, acFormatPDF, strFileFullPath

错误

Microsoft Access can't save the output data to the file you've selected.

我很确定会发生这种情况,因为宏 运行 与后台的其他用户有关。我一直在寻找解决方案,但我发现这是不可能的,我应该换用其他打印方法,例如 PDF Creator(这会带来很多其他问题)。

我在 Windows Server 2012 R2 Standard 中使用 Access 2016。

这听起来很疯狂,但在几天没有结果后,我通过创建这两个空文件夹设法解决了我的问题:

  • C:\Windows\System32\config\systemprofile\Desktop
  • C:\Windows\SysWOW64\config\systemprofile\Desktop

本页底部Faye评论的所有学​​分:https://blogs.technet.microsoft.com/askperf/2015/02/18/help-my-scheduled-task-does-not-run/

虽然评论是关于 Excel,但它解决了我在 Access 上的问题。这似乎与 Office 在非交互模式(这是任务计划程序在选中 "Run whether user is logged on or not" 时运行的模式)下遇到 运行 某些进程(在我的例子中是 pdf 生成)时遇到问题有关。