Yes, I needed hyperlinks, so I figured I would copy text from the web. I copied my test paragraphs from Google news.Originally Posted by TonyJollans
drumroll please....
you are right! (thank god, because I really wanted .sentences(1) to work!!!)
when I manually type the same headings and other text, the macro "grabs" the correct pieces of text.
however, when I use the stuff I pasted from the web, the macro grabs the whole mini-article!
Here's a tester for you. I butchered my original macro so it looks like this:
[vba]Sub TestingSentenceSelection()
TargetWord = Trim(InputBox("Enter the word that will be used to select sentences:"))
If TargetWord = "" Then MsgBox "No word entered." & vbCr & vbCr & "EXITING MACRO": End
Set myOriginalDoc = ActiveDocument
myOriginalDoc.Bookmarks("\StartOfDoc").Select
'****Set search parameters***************
Selection.Find.ClearFormatting
With Selection.Find
.MatchWildcards = False
.Text = "": .Replacement.Text = "": .Forward = True: .Wrap = wdFindStop
.Format = False: .MatchCase = False: .MatchWholeWord = False
.MatchSoundsLike = False: .MatchAllWordForms = False
End With
'****************************************
Selection.Find.Text = TargetWord
myBoolean = Selection.Find.Execute
If myBoolean = True Then Selection.Sentences(1).Select: MsgBox "I have selected the sentece"
End Sub[/vba]
run the macro and search for "Houston," and you will now see that the macro runs correctly. (because I manually typed the Houston article)
then run the macro and search for "Xinhua" (see 2nd article) and watch how the whole thing gets selected.