title: Word Macro to save as PDF when file saves
body: <p>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.</p>
  
  <p>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:</p>
  
  <pre><code>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
  </code></pre>