在任务计划程序“ExportAsFixedFormat”中运行时出现WINWORD错误

时间:2018-03-29 18:54:41

标签: powershell ms-word taskscheduler

我有一个PowerShell脚本,利用MS Word将txt文件转换为.pdf。在PowerShell窗口中执行脚本时没有问题 - 脚本工作正常并按照预期执行操作。但是,在将文档导出为.pdf时,从任务计划程序MS Word中执行此脚本失败。要清楚,脚本是作为计划任务执行的,我知道这是因为我将所有脚本输出发送到脚本文件。在脚本文件中,我在此行看到以下错误:

$doc.ExportAsFixedFormat( $outputFullPath , $wdExportFormatPDF )

这是错误。

PS>TerminatingError(Convert-Txt2Pdf): "Exception calling "ExportAsFixedFormat" with "2" argument(s): "Word has encountered a problem.""
Error Caught
Convert-Txt2Pdf : Exception calling "ExportAsFixedFormat" with "2" argument(s): "Word has encountered a problem."
At C:\Source\PowerShell\RunScripts\Run-Txt2Pdf2SP.ps1:55 char:9
+         Convert-Txt2Pdf `
+         ~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Convert-Txt2Pdf], MethodInvocationException
    + FullyQualifiedErrorId : COMException,Convert-Txt2Pdf

Inner Exception
   at Microsoft.Office.Interop.Word.DocumentClass.ExportAsFixedFormat(String OutputFileName, WdExportFormat ExportForma
t, Boolean OpenAfterExport, WdExportOptimizeFor OptimizeFor, WdExportRange Range, Int32 From, Int32 To, WdExportItem It
em, Boolean IncludeDocProps, Boolean KeepIRM, WdExportCreateBookmarks CreateBookmarks, Boolean DocStructureTags, Boolea
n BitmapMissingFonts, Boolean UseISO19005_1, Object& FixedFormatExtClassPtr)
   at CallSite.Target(Closure , CallSite , Object , Object , Object )

我在事件查看器中找不到任何内容,并且不知道问题是什么。可能导致此错误的原因是什么? 感谢

0 个答案:

没有答案