Dieses Forum nutzt Cookies
Dieses Forum verwendet Cookies, um deine Login-Informationen zu speichern, wenn du registriert bist, und deinen letzten Besuch, wenn du es nicht bist. Cookies sind kleine Textdokumente, die auf deinem Computer gespeichert werden. Die von diesem Forum gesetzten Cookies werden nur auf dieser Website verwendet und stellen kein Sicherheitsrisiko dar. Cookies aus diesem Forum speichern auch die spezifischen Themen, die du gelesen hast und wann du zum letzten Mal gelesen hast. Bitte bestätige, ob du diese Cookies akzeptierst oder ablehnst.

Ein Cookie wird in deinem Browser unabhängig von der Wahl gespeichert, um zu verhindern, dass dir diese Frage erneut gestellt wird. Du kannst deine Cookie-Einstellungen jederzeit über den Link in der Fußzeile ändern.

VBA PDF to TXT
#1
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
Antworten Top
#2
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
.      \\\|///      Hoffe, geholfen zu haben.
       ( ô ô )      Grüße, André aus G in T  
  ooO-(_)-Ooo    (Excel 97-2019+365)
[-] Folgende(r) 1 Nutzer sagt Danke an schauan für diesen Beitrag:
  • Oxirrinko
Antworten Top
#3
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
Antworten Top
#4
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 ... )
.      \\\|///      Hoffe, geholfen zu haben.
       ( ô ô )      Grüße, André aus G in T  
  ooO-(_)-Ooo    (Excel 97-2019+365)
Antworten Top
#5
Thanks again for your feedback. I modified the text and get the following error (see enclosed JPG).
Best regards


Angehängte Dateien Thumbnail(s)
   
Antworten Top
#6
Hello

sorry, the name of the variable is different. Sad

strFile <> PDFfile

Take the same name in all 3 codelines with them.
.      \\\|///      Hoffe, geholfen zu haben.
       ( ô ô )      Grüße, André aus G in T  
  ooO-(_)-Ooo    (Excel 97-2019+365)
Antworten Top


Gehe zu:


Benutzer, die gerade dieses Thema anschauen: 1 Gast/Gäste