title: Saving Word document as PDF
body: <p>This is related to converting a Word document to PDF format.</p>
  
  <p>I get an error in my Excel VBA code.</p>
  
  <blockquote>
    <p>Run-time error "5": Invalid procedure call or argument</p>
  </blockquote>
  
  <p>Saving into a Word document works</p>
  
  <pre><code>objWord.ActiveDocument.SaveAs PathName &amp; NewFileName &amp; ".docx"
  </code></pre>
  
  <p>The below runs but it creates a PDF document which is very big in size.</p>
  
  <pre><code>objWord.ActiveDocument.SaveAs2 Filename:=PathName &amp; NewFileName &amp; ".pdf", _ 
    FileFormat:=wdFormatPDF
  </code></pre>
  
  <p>I recorded a macro in Word to save the file as PDF and modified the generated code as per below.</p>
  
  <pre><code>objWord.ActiveDocument.ExportAsFixedFormat OutputFileName:= _
    PathName &amp; NewFileName &amp; ".pdf", _
    ExportFormat:=wdExportFormatPDF, OpenAfterExport:=False, OptimizeFor:= _
    wdExportOptimizeForPrint, Range:=wdExportAllDocument, From:=1, To:=1, _
    Item:=wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, _
    CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _
    BitmapMissingFonts:=True, UseISO19005_1:=False
  </code></pre>
  
  <p>I am using Excel VBA to do a Mailmerge using Word document and it is working fine and able to save individual documents in Word format but I need to save it in PDF format.</p>