title: vba converting multiple pdf in folder to text file
body: <p>I was trying to run a vba to convert multiple pdf file in a folder into txt file in another folder. however, I encountered the following error which I was not able to resolve. </p>
  
  <p>The error is at Set jsObj = AcroXPDDoc.GetJSObject which gave me a runtime error 91: "Object variable or With block variable not set"    </p>
  
  <p>Can anyone help?
  Thanks.</p>
  
  <p>:Updated with new code</p>
  
  <pre><code>Option Explicit
  
  Sub convertpdf5()
  
   Dim AcroXApp As Acrobat.acroApp
   Dim AcroXAVDoc As Acrobat.AcroAVDoc
   Dim AcroXPDDoc As Acrobat.AcroPDDoc
   Dim Filename As Variant
   Dim jsObj As Object
   Dim sfolder As String
   Dim dfolder As String
   Dim spath As String
   Dim dpath As String
   Dim SFilename As Variant
   Dim DFilename As Variant
   Dim objFolder As folder
   Dim objFile As file
   Dim NextRow As Long
  
  sfolder = "C:\users\chanhc\desktop\test folder\"
  spath = sfolder &amp; "*.pdf"
  SFilename = Dir(spath)
  
  dfolder = "C:\users\chanhc\desktop\test folder after\"
  dpath = dfolder &amp; "*.txt"
  DFilename = Dir(dpath)
  
  'Creating a FileSystemObject
  Dim fso As New FileSystemObject
  'Specify the path of the folder
  'Create the object of this folder
  Set objFolder = fso.GetFolder(sfolder)
  'Check if the folder is empty or not
  If objFolder.Files.count = 0 Then
    MsgBox "No files were found...", vbExclamation
    Exit Sub
  
  End If
  
  NextRow = ActiveSheet.Cells(Rows.count, "A").End(xlUp).Row + 1
  
  For Each objFile In objFolder.Files
  
  Cells(NextRow, 1).Value = sfolder &amp; objFile.Name
  
  NextRow = NextRow + 1
  
  Next objFile
  
  For Each Filename In Sheet1.Range("a2:a4")
  
   Set AcroXApp = CreateObject("AcroExch.App")
   'AcroXApp.Show
   Set AcroXAVDoc = CreateObject("AcroExch.AVDoc")
   AcroXAVDoc.Open Filename, "Acrobat"
   Set AcroXPDDoc = AcroXAVDoc.GetPDDoc
   Set jsObj = AcroXPDDoc.GetJSObject
   jsObj.SaveAs DFilename, "com.adobe.acrobat.plain-text"
  
  
   AcroXAVDoc.Close False
   AcroXApp.Hide
   AcroXApp.Exit
  
  Next Filename
  
  End Sub
  </code></pre>