Open PDF, replace text in text box, save,close

jpsimmon

New Member
Joined
Apr 9, 2015
Messages
28
Trying to open a PDF that has a fillable text field and link it with a cell, this is the best i have found, but it just seems to be opening my PDF and not adjusting the text.
Code:
[/COLOR]
Sub AcrobatFindText2() <o:p></o:p>
<o:p></o:p>
'variables<o:p></o:p>
Dim Resp 'For message box responses<o:p></o:p>
Dim gPDFPath As String<o:p></o:p>
Dim sText As String 'String to search for<o:p></o:p>
Dim sStr As String 'Message string<o:p></o:p>
Dim foundText As Integer 'Holds return value from "FindText" method<o:p></o:p>
<o:p></o:p>
'hard coding for a PDF to open, it can be changed when needed.<o:p></o:p>
gPDFPath = "C:\Users\Me\Documents\test.pdf"<o:p></o:p>
<o:p></o:p>
'Initialize Acrobat by creating App object<o:p></o:p>
Set gApp = CreateObject("AcroExch.App", "")<o:p></o:p>
gApp.Hide<o:p></o:p>
<o:p></o:p>
'Set AVDoc object<o:p></o:p>
Set gAvDoc = CreateObject("AcroExch.AVDoc")<o:p></o:p>
<o:p></o:p>
' open the PDF<o:p></o:p>
If gAvDoc.Open(gPDFPath, "") Then<o:p></o:p>
sText = "Designation"<o:p></o:p>
'FindText params: StringToSearchFor, caseSensitive (1 or 0), WholeWords (1 or 0), 'ResetSearchToBeginOfDocument (1 or 0)<o:p></o:p>
foundText = gAvDoc.FindText(sText, 1, 0, 1) 'Returns -1 if found, 0 otherwise<o:p></o:p>
<o:p></o:p>
Else ' if failed, show error message<o:p></o:p>
Resp = MsgBox("Cannot open" & gPDFPath, vbOKOnly)<o:p></o:p>
<o:p></o:p>
End If<o:p></o:p>
<o:p></o:p>
If foundText = -1 Then<o:p></o:p>
<o:p></o:p>
'compose a message<o:p></o:p>
sStr = "Found " & sText<o:p></o:p>
Resp = MsgBox(sStr, vbOKOnly)<o:p></o:p>
Else ' if failed, 'show error message<o:p></o:p>
Resp = MsgBox("Cannot find" & sText, vbOKOnly)<o:p></o:p>
End If<o:p></o:p>
<o:p></o:p>
gApp.Show<o:p></o:p>
gAvDoc.BringToFront<o:p></o:p>
<o:p></o:p>
End Sub
Can anyone help?
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.

Forum statistics

Threads
1,214,865
Messages
6,121,988
Members
449,060
Latest member
mtsheetz

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