Consulting

Results 1 to 2 of 2

Thread: Copying from PDFs - Only pastes last file?

  1. #1

    Copying from PDFs - Only pastes last file?

    Hi everybody! I have this code:

    Sub Sheet2_Button1_Click()
    Dim strPath As String
    Dim MyFile As String
    Dim Adobefile
    Dim sep As String: sep = Application.PathSeparator
    Dim shTemp As Worksheet: Set shTemp = Worksheets("Temp")
    Dim shMain As Worksheet: Set shMain = Worksheets("Main")
    strPath = "C:\Users\jkb\Desktop\PDF"
    MyFile = Dir(strPath & sep & "*.pdf")
    Do While MyFile <> ""
        ActiveWorkbook.FollowHyperlink strPath & sep & MyFile
        SendKeys ("^a")
        SendKeys ("^c")
        Application.Wait (Now + TimeValue("00:00:01"))
        SendKeys "%{F4}", True
        AppActivate "Microsoft Excel"
        shTemp.Activate
        ActiveSheet.Range("A1").Select
        SendKeys ("^v")
        MyFile = Dir()
    Loop
    End Sub
    In the folder PDF i have 3 pdfs, my problem is that it only pastes the last one of them, i can see it opens all 3, and at least selects everything in the sheet, but only pastes the last file into excel. In general i think using adobe reader in excel is super annoying! Earlier it didnt close the files after opening, then i found that making it wait a second before pressing alt+f4 was the solution... Any ideas to how i can make it paste all documents into excel?

    - In general my code is super unstable... If any tips on how i can make it more stable, it would also be much appreciated. First time using Adobe from VBA.!

  2. #2
    I somehow managed to solve the problem myself. It seems that "SendKeys ("^v")" was a bad idea. Using activecell.pastespecial it worked!

    But if anybody have some experience in extracting data from a bunch of PDFs, feel free to share!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •