title: How to convert pdf to xlsx using Excel VBA
body: <p>I am trying to convert a pdf file to an excel file (xlsx) using excel VBA.</p>
  <p>The problem is the code seems to be perfectly fine as I have seen it working on other computers in action, but for some reason, I am getting a run time error and I am trying to solve this for a week.</p>
  <p>Below is the code</p>
  <pre><code> Option Explicit
  Function ClearCipboard()
  'Early binding will requires a Reference to 'Microsoft Forms 2.0 Object Library'
      Dim oData                 As Object    'New MSForms.DataObject
  
      Set oData = CreateObject(&quot;New:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}&quot;)
      oData.SetText Text:=Empty
      oData.PutInClipboard
      Set oData = Nothing
  End Function
  Sub Automate()
  
  Dim PathforPDFfiles As String
  Dim PathforExcelfiles As String
  
  PathforPDFfiles = &quot;C:\Users\kvenkat2\Desktop\Trails 18.06.2021\Test File Excel\PDF-to-Excel-Converter\&quot;
  PathforExcelfiles = &quot;C:\Users\kvenkat2\Desktop\Trails 18.06.2021\Test File Excel\PDF-to-Excel-Converter\&quot;
  
  Dim fso As New FileSystemObject
  Dim myFolder As Folder
  Dim myFile As File
  
  Set myFolder = fso.GetFolder(PathforPDFfiles)
  
  Dim WordApp As Object
  Dim WordDoc As Object
  Dim WordRange As Object
  
  Application.DisplayAlerts = False
  Application.ScreenUpdating = False
  
  Set WordApp = CreateObject(&quot;word.application&quot;)
  'Set WordDoc = WordApp.documents.Add
  'Set WordApp = New Word.Application
  WordApp.Visible = True
  
  Dim nwb As Workbook
  Dim nsh As Worksheet
  
  For Each myFile In myFolder.Files
  Set WordDoc = WordApp.documents.Open(myFile.Path, False, Format:=&quot;PDF Files&quot;)
  Set WordRange = WordDoc.Paragraphs(1).Range
  WordRange.WholeStory
  
  Set nwb = Workbooks.Add
  Set nsh = nwb.Sheets(1)
  WordRange.Copy
  nsh.Paste
  nwb.SaveAs (PathforExcelfiles &amp; Replace(myFile.Name, &quot;.pdf&quot;, &quot;.xlsx&quot;))
  
  Application.CutCopyMode = False
  Call ClearCipboard
  WordDoc.Close True
  nwb.Close True
  Next
  
  WordApp.Quit
  Set WordDoc = Nothing
  Set WordApp = Nothing
  
  Application.displayAlters = True
  Application.ScreenUpdating = False
  
  MsgBox (&quot;Done for real&quot;)
  End Sub
  </code></pre>
  <p><code>Set WordDoc = WordApp.documents.Open(myFile.Path, False, Format:=&quot;PDF Files&quot;)</code></p>
  <p>This is the part where my code stops running and I try to see the opened word and nothing happens from here. I am unable to get past this line.</p>
  <p>It shows as a run time error as shown in the image <a href="https://i.stack.imgur.com/81GuR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/81GuR.png" alt="enter image description here" /></a></p>