当任务计划程序设置为“运行用户是否登录"时,VBA失败. [英] VBA fails when Task Scheduler is set to "Run whether user logged on or not"

查看:594
本文介绍了当任务计划程序设置为“运行用户是否登录"时,VBA失败.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Access VBA宏,它可以生成报告,将其保存为.pdf,然后使用CDO通过电子邮件发送.如果我手动运行它,或者将其设置为在任务计划程序上使用安全选项仅在用户登录时运行",则一切正常.但是,如果我将选项设置为无论用户是否登录都运行"(即使使用选项以最高特权运行"),程序也会在以下内容的第二行崩溃:

I have an Access VBA macro that generates a report, saves it in .pdf and then sends it by e-mail using CDO. Everything works fine if I run it manually or if I set it to be run on Task Scheduler with the security option "Run only when user is logged on". However, if I set the option to "Run whether user is logged on or not" (even with the option "Run with highest privileges") the program crashes on the second line of:

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

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

错误

Microsoft Access无法将输出数据保存到您拥有的文件中 选择.

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

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

I am pretty sure that this happens because the macro runs with other user in the background. I have been searching for a solution but all I have found is that it is not possible and that I should change for other printing methods, such as PDF Creator (which brings a lot of other issues).

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

I am using Access 2016 in Windows Server 2012 R2 Standard.

推荐答案

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

It sounds crazy, but after a few days with no results, I managed to solve my problem just by creating these two empty folders:

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

此页面底部对Faye的评论全部归功于:

All the credits to Faye's comment on the bottom of this page: https://blogs.technet.microsoft.com/askperf/2015/02/18/help-my-scheduled-task-does-not-run/

尽管注释涉及Excel,但它解决了我关于Access的问题.似乎与Office在非交互模式(检查运行是否登录用户"时任务计划程序运行的模式)下运行某些进程(在我的情况下为pdf生成)时遇到麻烦有关

Although the comment regards Excel, it solved my issue on Access. It seems that is related with Office having trouble with running some processes (in my case, a pdf generation) in non-interactive mode (which is the mode that Task Scheduler runs when "Run whether user is logged on or not" is checked).

这篇关于当任务计划程序设置为“运行用户是否登录"时,VBA失败.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆