3 Replies Latest reply: Feb 5, 2013 9:52 AM by Test Screen Name RSS

    Access 2007 VBA help to loop through text and pull whole words in a PDF

    RobertJ.Baker Community Member

      I have VBA code inside Acces 2007 on a Windows machine with Adobe 9 that lets me loop through a PDF using VBA to scan text looking for matches on words. I have Adobe 10 reader (not pro extended).

       

      Right now what I ham trying to do is either find text in the objects, or pull text values from a PDF, then pull the whole word where it is found. Here is a quick example: I am looking for any word that starts with 'for'. So I might find formula, form, fort, fortune and so on.  So not only do I want to find the word, but I want to pull it in its entirety

       

      My original code had AVDoc.FindText("for",0,0,1). This would give me a TRUE or FALSE on whether it found the word, not its location or any way to extract the whole word and where it was found.

       

      So now my issue is that due to several variations to templates that were used to make hundreds of new PDF's, the text I need to find is either in a text field, or the label of a button in the PDF. I have put together some code I found online that gives me the name of the object and its value, but I can not see any properties, IE I know it is a button, but I do not know how view the text inside the button.

       

      Here is the code I am currently using on a machine with Access 2007 and Adobe Pro Extended 10 ( I found pro is needed to avoid the 429 error ActiveX component can't create object when trying to CreateObject)

       

       

      ////////////////////////////////////////////////

      Private Sub Command0_Click()

      Dim PDFApp As Acrobat.AcroApp

      Dim AVDoc As Acrobat.AcroAVDoc

      Dim PDDoc As Acrobat.AcroPDDoc

       

      Set PDFApp=CeateObject("AcroExch.App")

      Set AVDoc=CreateObject("AcroExch.AvDoc")

       

      AVDoc.Open "Z:\Desktop\Adobe VBA.PDF", ""

      Set PDDoc =AVDoc.GetPDDoc

      Dim FN As String

      Dim F As Variant

      Dim FV As String    

      '----------------------Borrowed Code-----------------------

      Set JSO =PDDoc.GetJSObject

           For i = 0 To JSO.NumFields -1

                FN =JSO.GetNthFieldName(i)

                Set F=JSO.Field(FN)

                FV=F.Value

           Next i

      '---------------------Borrowed Code------------------------

       

      Set F= Nothing

      Set PDDoc = Nothing

      Set AVDoc = Nothing

      Set PDFApp = Nothing

       

      End Sub

       

      ///////////////////////////////////////////////////////////////////////////////////////