Open PDF File and Perform Text Search Using excel vba -


i need develop simple excel vba application data validation. have excel files employee information , need validate information against source document ( pdf file(s)). information in excel grouped employee name.

is possible write vba script open specified pdf file, allow user perform search of employee name pdf jumps appropriate employee page? (each employee has individual page in pdf document.) once on employee page user review data, make necessary edits excel file , search next employee.

i believe can use:

sub navigatepdf()  thisworkbook.followhyperlink "c:\user\target.pdf"  end sub 

to open pdf file, don't know how issue search excel vba once have file open.

can offer suggestions or point me useful resoucres.

some additional research yielded application written christos samaras. tool uses excel vba open specified pdf , highlight provided search term. possibly downside requirement adobe pdf pro - code not work acrobat reader.

here link , code:

option explicit  sub findtextinpdf()      '----------------------------------------------------------------------------------------     'this macro can used find specific text (more 1 word) in pdf document.     'the macro opens pdf, finds specified text (the first instance), scrolls     'that visible , highlights it.     'the macro uses findtext method (see code below more info).      'note in cases doesn't work (doesn't highlight text), in     'cases prefer searchtextinpdf macro, if have 1 word find!      'the code uses late binding, no reference external library required.     'however, code works adobe professional, don't try use     'adobe reader because "activex component can't create object" error.      'written by:    christos samaras     'date:          04/05/2014     'e-mail:        xristos.samaras@gmail.com     'site:          http://www.myengineeringworld.net     '----------------------------------------------------------------------------------------      'declaring necessary variables.     dim texttofind  string     dim pdfpath     string     dim app         object     dim avdoc       object      'specify text wawnt search.     'texttofind = "christos samaras"     'using range:     texttofind = thisworkbook.sheets("pdf search").range("c5").value      'specify path of sample pdf form.     'full path example:     'pdfpath = "c:\users\christos\desktop\how software companies die.pdf"     'using workbook path:     'pdfpath = thisworkbook.path & "\" & "how software companies die.pdf"     'using range:     pdfpath = thisworkbook.sheets("pdf search").range("c7").value      'check if file exists.     if dir(pdfpath) = ""         msgbox "cannot find pdf file!" & vbcrlf & "check pdf path , retry.", _                 vbcritical, "file path error"         exit sub     end if      'check if input file pdf file.     if lcase(right(pdfpath, 3)) <> "pdf"         msgbox "the input file not pdf file!", vbcritical, "file type error"         exit sub     end if      on error resume next      'initialize acrobat creating app object.     set app = createobject("acroexch.app")      'check if object created. in case of error release object , exit.     if err.number <> 0         msgbox "could not create adobe application object!", vbcritical, "object error"         set app = nothing         exit sub     end if      'create avdoc object.     set avdoc = createobject("acroexch.avdoc")      'check if object created. in case of error release objects , exit.     if err.number <> 0         msgbox "could not create avdoc object!", vbcritical, "object error"         set avdoc = nothing         set app = nothing         exit sub     end if      on error goto 0      'open pdf file.     if avdoc.open(pdfpath, "") = true          'open successful, bring pdf document front.         avdoc.bringtofront          'use findtext method in order find , highlight desired text.         'the findtext method returns true if text found or false if not.         'here 4 arguments of findtext methd:         'text find:          text found (in example texttofind variable).         'case sensitive:        if true, search case-sensitive. if false, case-insensitive (in example true).         'whole words only:      if true, search matches whole words. if false, matches partial words (in example true).         'search 1st page:  if true, search begins on first page of document. if false, begins on current page (in example false).         if avdoc.findtext(texttofind, true, true, false) = false              'text not found, close pdf file without saving changes.             avdoc.close true              'close acrobat application.             app.exit              'release objects.             set avdoc = nothing             set app = nothing              'inform user.             msgbox "the text '" & texttofind & "' not found in pdf file!", vbinformation, "search error"          end if      else          'unable open pdf file, close acrobat application.         app.exit          'release objects.         set avdoc = nothing         set app = nothing          'inform user.         msgbox "could not open pdf file!", vbcritical, "file error"      end if  end sub 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -