title: Embedding PDFs through VBA
body: <p>I am trying to programatically embed PDF files to specific worksheets. When I embed using the ClassType variable "Adobe.Document.2015", the file opens without problems, however, I have to manually paste in the filepath. When I embed using the filename argument of OLEObjects.Add, I can do it programmatically, however, when the user opens the PDF document embedded this way, they get an error message on the Acrobat side. This message does not appear when adding through the ClassType argument of OLEObjects.Add. Is there a way to use both ClassType and Filename arguments so I don't have to manually paste the file paths?</p>
  
  <p>I am at a loss as I have attempted Application.SendKeys but it is executed after the OLEObjects.Add method is resolved, not during. Appreciate any help.</p>
  
  <p><a href="https://i.stack.imgur.com/VaHLn.png" rel="nofollow noreferrer">Adobe Acrobat Error Message</a></p>
  
  <pre><code>Sub OLE_Objects_Fix()
  
  Dim OLE As Excel.OLEObject
  Dim OLEs As Excel.OLEObjects
  
  Dim Xl As New Excel.Application
  Dim Ws As Excel.Worksheet
  Dim Wb As Excel.Workbook
  Dim dirPath, fileName, filePath As String
  Dim Rng As Excel.Range
  
  Set Rng = Summary.Range("A1")
  
  dirPath = "C:\Users\me\Desktop\...\Models\"
  fileName = VBA.Dir(dirPath, vbNormal)
  
  With Xl
      .Visible = True
      While fileName &lt;&gt; ""
          If VBA.Left(fileName, 9) = "unique identifier" Then
              Debug.Print fileName
              Set Wb = .Workbooks.Open(dirPath &amp; fileName, False, False)
                  For Each Ws In Wb.Worksheets
                      Ws.Activate
                      Set Rng = Rng.Offset(1, 0)
                      If Ws.Name = Rng.Offset(0, 1).Value Then
                          filePath = Rng.Offset(0, 3).Value
                      End If
                      For Each OLE In Ws.OLEObjects
                          OLE.Delete
                      Next OLE
                          If filePath &lt;&gt; "" Then
                              Debug.Print Ws.Name: Debug.Print filePath
                              Set OLEs = Ws.OLEObjects
                              Set OLE = OLEs.Add( _
                              fileName:=filePath, _
                              Link:=False, _
                              DisplayAsIcon:=False, _
                              Left:=Ws.Range("F1").Left, _
                              Top:=Ws.Range("F1").Top)
                          End If
                  Next Ws
              filePath = ""
              Wb.Close (True)
          End If
          fileName = VBA.Dir
      Wend
  
  End With
  
  End Sub
  </code></pre>