title: VBA: Within Excel how do I save a word document as a PDF?
body: <p>I have some code that copies and pastes data from an Excel file into a word document, how can I get that word document to save as a PDF?</p>
  
  <p>My code is as follows:</p>
  
  <pre><code>Sub RetailerGraphs()
  
  Dim Location As String
  Dim Detail As String
  
  Worksheets("-Summary").Activate
  Range("AE9").Select
  While ActiveCell.Value &lt;&gt; ""
      ActiveCell.Offset(1, 0).Select
      Location = ActiveCell.Value
      Worksheets("Detail Summary").Activate
      Range("B7").Value = Location
  
      Dim objWord, objDoc As Object
      ActiveWindow.View = xlNormalView
      Set objWord = CreateObject("Word.Application")
      Set objDoc = objWord.Documents.Add
  
      Range("AH40").Select
      While ActiveCell &lt;&gt; ""
          ActiveCell.Offset(1, 0).Select
          Detail = ActiveCell.Value
          Range("B11").Value = Detail 
          Application.Wait (Now + TimeValue("0:00:05"))
          Range("A1:Z111").CopyPicture Appearance:=xlScreen, Format:=xlPicture
          objWord.Visible = True
          objWord.Selection.Paste
          objWord.Selection.TypeParagraph
          Set objSelection = objWord.Selection
          objSelection.InsertBreak (wdPageBreak)
          If ActiveCell.Value = "END" Then
               objWord.SaveAs2 "C:\Docs\MyDoc.pdf"
          End If
      Wend
      Worksheets("-Summary").Activate
  Wend
  
  End Sub
  </code></pre>
  
  <p>Within the lines:</p>
  
  <pre><code>If ActiveCell.Value = "END" Then
  
  End If
  </code></pre>
  
  <p>I have tried the following code to try to get it to save as a PDF:</p>
  
  <pre><code> objWord.ExportAsFixedFormat OutputFileName:="C:\wordtest.pdf", _
    ExportFormat:=wdExportFormatPDF
  
   objWord.ExportAsFixedFormat OutputFileName:="C:\Documents and Settings\All Users\Desktop\YourFile.pdf", ExportFormat:=wdExportFormatPDF
  
   objDoc.ExportAsFixedFormat OutputFileName:="C:\Documents and Settings\All Users\Desktop\YourFile.pdf", ExportFormat:=wdExportFormatPDF
  </code></pre>
  
  <p>But I get the error on the line where I try to export it as a PDF, e.g. <code>objWord.SaveAs2 "C:\Docs\MyDoc.pdf"</code> :</p>
  
  <pre><code>Run-time error '438':
  Object doesn't support this property or method
  </code></pre>
  
  <p>Can someone please help?</p>
  
  <p>Note: I have ensured that "Microsoft Word 14.0 Object Library" is ticked in the references, and I change the location to the necessary directory rather than using the above.</p>