Hi,
I am using some code I found online to find a text string in a PDF. -
-
Private Sub Command3_Click()
-
'IAC objects
-
Dim gAvDoc As Object
-
-
'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 = "C:\Documents and Settings\user\Desktop\testsearchpdf.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 = "SD15"
-
'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
-
What I need to do is select the text that is to the right of the text string, lets say 15 characters that appear to the right of the string. Any suggestions?
Thanks,
RugbyKorn
Do you have any suggestions for how I can turn the entire contents of the PDF into a string so that I can then use the inStr function?
I know of no such Method to accomplish this.
8 4084 Rabbit 12,516
Recognized Expert Moderator MVP
Use the Right function.
Where # is how many characters you want from the right.
Hi Rabbit,
I appreciate you taking the time to review my post. I was hoping it would be that simple but here is what I ran into. The code I pasted uses - gAvDoc.FindText("String", 1, 0, 1)
to locate the string I want. However that function is simply a true false (0 or 1) as to whether the string I specify exists. What I need to do is search for the "string" and anything to the right of it, so something like
. However I can't use the FindText function since that will simply tell me if the string exists, and not what is contained in the wildcard section of it.
I hope this makes sense. I am more then happy to clarify anything I just wrote if you would like some more background on what I am trying to achieve.
Thanks!
ADezii 8,834
Recognized Expert Expert
Here is the Basic Logic for finding a Sub-String within a String, then outputting the 15 Characters after the Sub-String. The Code makes many Assumptions that I will not go into at this point. -
Const conTEST_String As String = "AAAAA AA AAAAA AAAAA AAARDK12YE YOU FOUND ME IGNORE THER EST^^&%OFTHIS"
-
Const conSTING_TO_FIND As String = "RDK12"
-
Dim intStartPos As String
-
-
intStartPos = InStr(conTEST_String, conSTING_TO_FIND)
-
-
If intStartPos = 0 Then Exit Sub
-
-
Debug.Print Mid$(conTEST_String, intStartPos + Len(conSTING_TO_FIND), 15)
OUTPUT (15 characters after Search String): Used within the Context of a Traditional Access Text Box: - Const conSTING_TO_FIND As String = "RDK12"
-
Dim intStartPos As String
-
-
intStartPos = InStr(Me![txtTest], conSTING_TO_FIND)
-
-
If intStartPos = 0 Then Exit Sub
-
-
With Me![txtTest]
-
.SetFocus
-
.SelStart = (intStartPos + Len(conSTING_TO_FIND)) - 1
-
.SelLength = 15
-
End With
@Rabbit I think that OP is wanting the characters TO the right not FROM the right, in which case the Mid() function would be needed. However, I don't see in the code provided how to get the string value. I only see that it says that it found the search string or not, but not where it would return the string found in the PDF.
Hi Seth,
Again, thank you everyone for taking a look at this as I would love to figure this out. At the bottom of the code a MsgBox is displayed showing the value that was searched for, but as you said its not displaying the actual value found. I know what I need to do, which is to search for a value, and identify the characters next to that value, say the 10 characters to the right of it. However I don't now how to index the whole PDF so that I can then use the inStr function as @ADezii suggested.
RugbyKorn
Hi @ADezii,
Do you have any suggestions for how I can turn the entire contents of the PDF into a string so that I can then use the inStr function?
RugbyKorn
ADezii 8,834
Recognized Expert Expert
Do you have any suggestions for how I can turn the entire contents of the PDF into a string so that I can then use the inStr function?
I know of no such Method to accomplish this.
@ADezii,
I'm thinking that may be a dead end. I am now trying to do this with an XPS document instead of a PDF. I will open a new comment thread. Thanks for taking the time to read.
RugbyKorn
Sign in to post your reply or Sign up for a free account.
Similar topics
by: cassandra.flowers |
last post by:
Hi,
I am using VB6 and want to extract text from a string. But ONLY take out
words that begin with 't' or 'd'. The mainstring is input by the user into
'txtMain' and then by clicking a command...
|
by: RelaxoRy |
last post by:
Is there any way to stop someone getting their mouse and selecting
text on a page (without making the text an image of course). Is it
possible to trap and stop click-and-drag functionality from...
|
by: Lloyd |
last post by:
I am trying to insert text in a text area. I need to insert one set of
values on the left side of the text area and have corresponding values
on the left side of the text area in an even column....
|
by: Kim |
last post by:
Hello,
I am selecting data from a text file with the following statement:
"INSERT INTO SELECT * FROM " & sSource & " IN '' " & _
"'text;Database=" & sPath & ";FMT=Delimited;HDR=No' " & _...
|
by: robboll |
last post by:
Using MS Access 2003 I am looking for a function that will search the
entire Tables Collection for a specific string in text or memo fields.
For example if I enter "widget" it interrogates the...
|
by: Dan Schumm |
last post by:
I'm relatively new to regular expressions and was looking for some help on a
problem that I need to solve. Basically, given an HTML string, I need to
highlight certain words within the text of the...
|
by: Coffee |
last post by:
I have asked this before, but the offered solution did not work.
I want to have a command button, that transfers any text from a textbox
to a variable which is an array. so that i can print out...
|
by: boris.smirnov |
last post by:
Hallo all,
I have tried for a couple of hours to solve my problem with re but I
have no success.
I have a string containing: "+abc_cde.fgh_jkl\n" and what I need to
become is...
|
by: Pete |
last post by:
I need to create a single query (Not a SQL query) against a single
table that counts the number of records in the table, where the single
field "tmp" contains specific string values
If the field...
|
by: dfirka |
last post by:
Dear Everyone,
Using a RichTextBox I need to replace text based on certain RTF codes found into the RTF string
I look for certain embedded (hidden) information using:
int i =...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |