Clever-Excel-Forum

Normale Version: VBA PDF to TXT
Du siehst gerade eine vereinfachte Darstellung unserer Inhalte. Normale Ansicht mit richtiger Formatierung.
Hello, can anyone help to remake following VBA to repeat the process (open a new PDF file, copy, paste into a new text file)
as many PDF files contains a folder?

Thanks in advance!



Code:
Public Sub Copy_and_Paste_From_PDF_File2()

    Dim AdobeApp As String
    Dim PDFfile As String
    Dim StartAdobe
   
    ActiveSheet.Cells.Clear
   
    AdobeApp = "C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe"   'Acrobat Reader
   
    PDFfile = "C:\path\to\Invoice 123.pdf"
   
    StartAdobe = Shell(Q(AdobeApp) & " " & Q(PDFfile), 1)
   
    'Wait 3 seconds to allow PDF to open
    Application.Wait DateAdd("s", 3, Now)
   
    'Select All and Copy from PDF
    SendKeys "^a^c", True
   
    'Wait 5 seconds to allow Select All and Copy to finish
    Application.Wait DateAdd("s", 5, Now)
   
    'Paste into Excel
    AppActivate Application.Caption
    ActiveSheet.Range("A1").Select
    SendKeys "^v", True
 
End Sub

Private Function Q(text As String) As String
    Q = Chr(34) & text & Chr(34)
End Function
Hello,

here is an example to loop trough a directory and message all pdf files in it separately.

Code:
Sub test()
Dim strFile As String
'get first pdf file
strFile = Dir("C:\Test\*.pdf")
'loop so long as pdf files exists
Do While strFile <> ""
  MsgBox strFile
  'get next file with dir parameter above
  strFile = Dir()
Loop
End Sub
Thanks for the feedback!
I tried to combine both VBA but i still get an error.
I want to copy text of each full PDF in a folder, and paste them into excel (on each new excel files with same title as the PDF, or even all above each other in the same excel sheet).
Is this possible?

Thanks in advance again and best regards




Public Sub Copy_and_Paste_From_PDF_File2()

    Dim AdobeApp As String
    Dim PDFfile As String
    Dim StartAdobe
    Dim strFile As String
 
    ActiveSheet.Cells.Clear
 
    AdobeApp = "C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe"  'Acrobat Reader
 
    strFile = Dir("C:\PDF\*.pdf")
 
    StartAdobe = Shell(Q(AdobeApp) & " " & Q(PDFfile), 1)
   
    'Wait 3 seconds to allow PDF to open
    Application.Wait DateAdd("s", 3, Now)
 
    'Select All and Copy from PDF
    SendKeys "^a^c", True
 
    'Wait 5 seconds to allow Select All and Copy to finish
    Application.Wait DateAdd("s", 5, Now)
 
    'Paste into Excel
    AppActivate Application.Caption
    ActiveSheet.Range("A1").Select
    SendKeys "^v", True
   
        Do While strFile <> ""
    MsgBox strFile
    strFile = Dir()
    Loop
End Sub

Private Function Q(text As String) As String
    Q = Chr(34) & text & Chr(34)
End Function
Hello,

I didn't work with adobe and so I can't say anything about adobe, but about other things.
So I have a question and a first point:


in which codeline you get the error and what is the error?


the correct position for
Do While strFile <> ""

is the line after first
strFile =


(Sometimes it's a little bit problematic with SENDKEYS ... )
Thanks again for your feedback. I modified the text and get the following error (see enclosed JPG).
Best regards
Hello

sorry, the name of the variable is different. Sad

strFile <> PDFfile

Take the same name in all 3 codelines with them.