[英]powershell - MS-Word document parsing - Get a table's caption text
[英]Setting Destination for Powershell MS-Word MailMerge
我一直在尝试解决这个“简单”的问题,但找不到问题的解决方案。
我正在尝试生成 powershell 脚本来运行 MS-WORD 邮件合并并将文档(最好是 pdf)导出到特定文件位置。 mailmerge 运行成功,但它不会生成新文档,而是打印到默认打印机。 我希望它生成一个新文档,然后我可以将它保存到提供的目的地。
$DocumentName = 'MailMerge.docx'
$OutputFilename = 'Output.pdf'
$word=new-object -com Word.Application
$word.Visible = 'True'
$doc=$word.Documents.Open($DocumentName)
$doc.WdMailMerge.Destination.wdSendToNewDocument
$doc.Mailmerge.Execute()
$word.ActiveDocument.SaveAs([ref] $Outputfilename, [ref] 17)
$Doc.close()
$word.Quit()
我猜我在邮件合并目的地做错了什么,但我在绕圈子。
提前感谢您提供的任何帮助。 (第一次发帖,请轻拍)
[编辑]总有一些重要的事情你会忘记。 逐步执行此操作时,它会在到达保存文档的行之前生成邮件合并打印。 当保存开始时,它是一个重命名原始邮件合并的单页文档。
这条线
$doc.WdMailMerge.Destination.wdSendToNewDocument
应该更像这样:
$doc.MailMerge.Destination = 0
或者要使用 Word 的内置常量,您应该能够做到这一点(在 @Theo 发表评论之后):
$doc.MailMerge.Destination = [Microsoft.Office.Interop.Word.WdMailMergeDestination]::WdSendToNewDocument
替换这一行:
$word.ActiveDocument.SaveAs([ref] $Outputfilename, [ref] 17)
通过这一行:
$doc.SaveAs([ref] $Outputfilename, [ref] 17)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.