Find word and goto page in PDF from Excel

terminatorgenx

New Member
Joined
Dec 14, 2012
Messages
1
Hi,

I have an Excel-2010 file which contains students unique admission number in column-A.
Everytime I click in any cell in column-A, the code below finds the student in the PDF file.

Need help with the following:
Everytime I click on a cell in column-A, it should find the student admission number in pdf and take me to that page (note every student has one page).


Code:
Sub AcrobatFindText2()

'variables
Dim Resp 'For message box responses
Dim gPDFPath As String
Dim sText As String 'String to search for
Dim sStr As String 'Message string
Dim foundText As Integer 'Holds return value from "FindText" method


'hard coding for a PDF to open, it can be changed when needed.
gPDFPath = "Example.pdf"


'Initialize Acrobat by creating App object
Set gApp = CreateObject("AcroExch.App", "")
gApp.Hide


'Set AVDoc object
Set gAvDoc = CreateObject("AcroExch.AVDoc")


' open the PDF
If gAvDoc.Open(gPDFPath, "") Then
    sText = "AB9991442" [U][I][B]'Students unique admission number[/B][/I][/U]
    'FindText params: StringToSearchFor, caseSensitive (1 or 0), WholeWords (1 or 0), 'ResetSearchToBeginOfDocument (1 or 0)
    foundText = gAvDoc.FindText(sText, 1, 0, 1) 'Returns -1 if found, 0 otherwise
Else ' if failed, show error message
    Resp = MsgBox("Cannot open" & gPDFPath, vbOKOnly)
End If


If foundText = -1 Then
    'compose a message
    sStr = "Found " & sText
    Resp = MsgBox(sStr, vbOKOnly)
Else ' if failed, 'show error message
    Resp = MsgBox("Cannot find" & sText, vbOKOnly)
End If


gApp.Show
gAvDoc.BringToFront


End Sub
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes

Forum statistics

Threads
1,216,366
Messages
6,130,192
Members
449,565
Latest member
excelqueenintraining

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top