+ Reply to Thread
Results 1 to 3 of 3

Open multiple PDF files from certain path

Hybrid View

  1. #1
    Registered User
    Join Date
    08-22-2012
    Location
    Townsville
    MS-Off Ver
    Excel 2010
    Posts
    38

    Open multiple PDF files from certain path

    Hi all,

    I have found a code that opens up a single pdf document and then from there I can save it as a txt file then open it and copy the text into excel. But I want to do it to multiple pdf files that are in the same folder - this part I'm having a problem with. So once it saves it as a text file open the first one up copy the data in column A, then loop to the next pdf save it as the same text file name that's ok then paste the data in column B.

    Any help would be much appreciated.

    Code below:
    Dim AcroXApp As Object
        Dim AcroXAVDoc As Object
        Dim AcroXPDDoc As Object
         
         
        Set AcroXApp = CreateObject("AcroExch.App")
        AcroXApp.Hide
         
         
        Set AcroXAVDoc = CreateObject("AcroExch.AVDoc")
        AcroXAVDoc.Open "C:\PDF test\blah.pdf", "Acrobat"
         
         
        AcroXAVDoc.BringToFront
         
         
        Set AcroXPDDoc = AcroXAVDoc.GetPDDoc
         
         
        Dim jsObj As Object
        Set jsObj = AcroXPDDoc.GetJSObject
         
         
        jsObj.SaveAs "C:\PDF test\test.txt", "com.adobe.acrobat.accesstext"
         
         
        AcroXAVDoc.Close False
        AcroXApp.Hide
        AcroXApp.Exit
    
    Dim Text
        Dim i As Long
    Worksheets("sheet2").Activate
    
    
        Application.ScreenUpdating = False
         'put your own path below
        Open ActiveWorkbook.Path & "\test.txt" For Input As #1
        i = 1
        Do While Not EOF(1) ' Loop until end of file.
            Input #1, Text
            Range("a" & i) = Text
            i = i + 1
        Loop
        Close #1

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Open multiple PDF files from certain path

    Untested, something like this to get you closer...

    Option Explicit
    
    Sub Test()
    Dim Text As String, Rw As Long, Col As Long
    Dim AcroXApp As Object, AcroXAVDoc As Object, AcroXPDDoc As Object, jsObj As Object
    Dim PDFpath As String, pdfNAME As String, wsDEST As Worksheet
    
    Application.ScreenUpdating = False
    Set AcroXApp = CreateObject("AcroExch.App")
    AcroXApp.Hide
    Set AcroXAVDoc = CreateObject("AcroExch.AVDoc")
        
    Set wsDEST = Sheets("Sheet2")           'sheet in activeworkbook to copy data into
    wsDEST.UsedRange.Clear                  'clear existing data from this worksheet
    Col = 1                                 'the first column to copy data into
    PDFpath = "C:\PDF test\"                'remember the final \ in this pdf path string
    pdfNAME = Dir(PDFpath & "*.pdf")        'get first filename from this path
    
    Do While Len(pdfNAME) > 0               'process one file at a time
        AcroXAVDoc.Open PDFpath & pdfNAME, "Acrobat"        'open first found pdf
        AcroXAVDoc.BringToFront
        Set AcroXPDDoc = AcroXAVDoc.GetPDDoc
        Set jsObj = AcroXPDDoc.GetJSObject
                                                            'save to text file of same name
        jsObj.SaveAs Replace(PDFpath & pdfNAME, ".pdf", ".txt"), "com.adobe.acrobat.accesstext"
    
        AcroXAVDoc.Close False              'close opened pdf
        AcroXApp.Hide
        AcroXApp.Exit
                                            'read in text file created one line at a time
        Open Replace(PDFpath & pdfNAME, ".pdf", ".txt") For Input As #1
        Rw = 1
        Do While Not EOF(1)                 'Loop until end of file.
            Input #1, Text                  'read a line
            wsDEST.Cells(Rw, Col) = Text    'write a line
            Rw = Rw + 1                     'incremenet to next row
        Loop
        Close #1                            'close opened text file
        Col = Col + 1
    
        pdfNAME = Dir                       'get next PDF filename from same path
    Loop                                    'repeat
    
    Application.ScreenUpdating = True
    End Sub
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    08-22-2012
    Location
    Townsville
    MS-Off Ver
    Excel 2010
    Posts
    38

    Re: Open multiple PDF files from certain path

    Awesome!! That worked.

    Thank you so much JBeaucaire!!!

    I just left the text file name as the one name though as I didn't want heaps of text files, just wanted them stored into excel.

    Thanks again!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Trying to Open Files Not Located in Specified Path
    By freybe06 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-06-2013, 12:40 AM
  2. VBA to search for multiple files in a path
    By clukens87 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-22-2013, 09:41 AM
  3. [SOLVED] VBA - Open Excel Files with file path from Named Ranges
    By bbg22 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 05-06-2012, 11:41 PM
  4. How to set GetOpenfile dialog start path to current open files path.
    By Michael Wise in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-03-2010, 02:24 PM
  5. importing multiple txt files from a selectable path
    By Boeiend in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-08-2005, 01:16 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1