Wordmacros保存为PDF文件保存时

我试图创build一个macros,当从Word(或Excel)2007+保存文件时执行。 macros需要检查文件的名称/位置以决定是否执行,然后如果文件名检出(可能是因为它附加了“_temp”,或存在于\ temp文件夹中),那么还需要保存文件,Word也以.pdf扩展名显示并保存到PDF中。 最好我希望在保存之前发生PDF,但是我没有受到影响。 Word客户端已经安装了SaveAsPDForXPS插件。

到目前为止,我已经弄清楚,我需要一个带有FileSave()处理程序的macros,并且(从录制testingmacros)保存位可能看起来像:

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 

好吧,我认为这是做这个工作,但是仍然感激地接受任何指向明显错误的指针。 另外,如何把它变成一个Addin仍然令人费解:

 Sub FileSave() ' ' FileSave Macro ' ActiveDocument.Save Dim StrFile As String Dim StrPath As String Dim StrName As String Dim StrPDFName As String StrPath = ActiveDocument.Path 'Get document path StrFile = ActiveDocument.Name 'Get document name If InStr(StrFile, "_tempkey") Then 'Check if this is a special file If InStr(StrFile, ".") Then StrName = Left(StrFile, (InStr(StrFile, ".") - 1)) Else StrName = StrFile End If StrPDFName = StrPath + "\" + StrName + ".pdf" ActiveDocument.ExportAsFixedFormat OutputFileName:=StrPDFName, _ ExportFormat:=wdExportFormatPDF, OpenAfterExport:=False, _ OptimizeFor:=wdExportOptimizeForPrint, Range:=wdExportAllDocument, _ Item:=wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, _ CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _ BitmapMissingFonts:=True, UseISO19005_1:=False End If End Sub