srh124
09-09-2015, 08:11 AM
Hi all.
I've been around my code for some days and it sounds i can't make it to work, as expected.
I wanna iterate through paragraphs and find ENGLISH WORDS in each paragraph , then do some work on them. It's necessary for this operation to be done on ONE paragraph, not the whole document.
This is my code:
For Each p In doc1.Paragraphs
EnglishCount = 0
Dim rng As Range
Set rng = p.Range
rng.Find.ClearFormatting
rng.Find.LanguageID = wdEnglishUS
With rng.Find
.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
End With
Do While rng.Find.Execute
EnglishCount = EnglishCount + 1
SelStartPos(EnglishCount) = rng.Start
SelEndPos(EnglishCount) = rng.End
MsgBox SelStartPos(EnglishCount) & " " & rng.Text
Loop
Next
The problem with my code is that it in every iteration of FOR..NEXT, it searches entire document and i want it to search in just specified paragraph
I've also used Selection object instead of Range, but no help.
Any help would be greatly appreciated. and Sorry for my english writing.
Regards
I've been around my code for some days and it sounds i can't make it to work, as expected.
I wanna iterate through paragraphs and find ENGLISH WORDS in each paragraph , then do some work on them. It's necessary for this operation to be done on ONE paragraph, not the whole document.
This is my code:
For Each p In doc1.Paragraphs
EnglishCount = 0
Dim rng As Range
Set rng = p.Range
rng.Find.ClearFormatting
rng.Find.LanguageID = wdEnglishUS
With rng.Find
.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
End With
Do While rng.Find.Execute
EnglishCount = EnglishCount + 1
SelStartPos(EnglishCount) = rng.Start
SelEndPos(EnglishCount) = rng.End
MsgBox SelStartPos(EnglishCount) & " " & rng.Text
Loop
Next
The problem with my code is that it in every iteration of FOR..NEXT, it searches entire document and i want it to search in just specified paragraph
I've also used Selection object instead of Range, but no help.
Any help would be greatly appreciated. and Sorry for my english writing.
Regards