文件保存时保存为 PDF 的 Word 宏
我正在尝试创建一个在从 Word(或 Excel)2007+ 保存文件时执行的宏。宏需要检查文件的名称/位置来决定是否执行,然后如果文件名签出(可能是因为它附加了“_temp”,或者存在于 \temp 文件夹中),则保存该文件,Word 也会保存为具有相同名称的 PDF,但显然带有 .pdf 扩展名。我最好希望在保存之前进行 PDF 处理,但我并不大惊小怪。 Word 客户端已安装 SaveAsPDForXPS 插件。
到目前为止,我已经设法弄清楚我需要一个带有 FileSave() 处理程序的宏,并且(通过记录测试宏)保存位可能如下所示:
Sub FileSave()
'
' FileSave Macro
'
'
ActiveDocument.ExportAsFixedFormat OutputFileName:= _
"C:\Documents and Settings\rdyce\Desktop\Doc1.pdf", ExportFormat:= _
wdExportFormatPDF, OpenAfterExport:=True, OptimizeFor:= _
wdExportOptimizeForPrint, Range:=wdExportAllDocument, From:=1, To:=1, _
Item:=wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, _
CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _
BitmapMissingFonts:=True, UseISO19005_1:=False
End Sub
I'm trying to create a macro that executes when a file is saved from Word (or Excel) 2007+. The macro needs ot check the name/location of the file to decide whether to execute, and then if the filename checks out (probably because it has '_temp' appended to it, or exists in the \temp folder) then as well as saving the file, Word also saves to PDF with the same name but obviously with the .pdf extension instead. Preferably I'd like the PDFing to happen prior to the save, but I'm not fussed. The Word client already has the SaveAsPDForXPS plug-in installed.
So far, I've managed to figure out that I need a macro with FileSave() handler in it, and that (from recording a test macro) the save bit might look like:
Sub FileSave()
'
' FileSave Macro
'
'
ActiveDocument.ExportAsFixedFormat OutputFileName:= _
"C:\Documents and Settings\rdyce\Desktop\Doc1.pdf", ExportFormat:= _
wdExportFormatPDF, OpenAfterExport:=True, OptimizeFor:= _
wdExportOptimizeForPrint, Range:=wdExportAllDocument, From:=1, To:=1, _
Item:=wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, _
CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _
BitmapMissingFonts:=True, UseISO19005_1:=False
End Sub
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,我认为这已经完成了工作,但仍然感激地收到任何指向明显错误的指示。另外,如何将其变成 Addin 仍然令人困惑:
OK, I think that this does the jjob, but any pointers to glaring errors still gratefully received. Also, how to turn it into an Addin is still proving puzzling: