Quote:
Originally Posted by gmayor
Looking for text between two very common characters such as '.' and '?' is bound to produce lots of false positives. It is necessary to narrow the search criteria.
In this example I would simply search for the string and remove the unwanted characters e.g.
Code:
Sub Macro1()
Const strFind As String = ". How are you today?"
Dim sText As String
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(findText:=strFind, _
MatchWildcards:=False, _
Wrap:=wdFindStop, _
Forward:=True) = True
sText = Replace(Selection.Range, ". ", "")
sText = Replace(sText, "?", "")
'do something with the found text e.g.
MsgBox sText
Loop
End With
lbl_Exit:
Exit Sub
End Sub
but see Replace using wildcards
|
Hi Gmayor.
I am sorry. Thanks for your reply.
The problem is this. The above question is an example (. How are you today?) I am not sure if that question "how are you today?" is in the word document. (However, it's only one question).
What I'm trying to accomplish is this? How can I extract all types of questions between 2 types and 2 groups of characters?
- . Question #1?
- , question #2?
- . Question #107? and so on...
Usually, questions in a paragraph have a period "." or a commo "," before the question and ends with a question mark "?".
I am sorry Gmayor, you mention. that the 2 characters "is bound to produce lots of false positives".
The question is, how am I going to work around this? What are other solutions do I have? How can I prevent "false positives"?
Thanks in advance
Cheers
Happy holiday