I am trying to replace words that are in all caps with a translated counterpart.
For example, I would like to replace the written number "ONE" with "UNO".
However, when "one" appears in the foreign language in various words it is replaced by "uno".
I only need to replace the capitalized word.
'ONE
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "ONE"
.Replacement.Text = "UNO"
.Forward = False
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchByte = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
A better option might be to replace when it shows up as the whole word.
Edit: You just set .MatchWholeWord to true.
To do this in bulk you might use code like:
Sub MultiFindReplace()
Application.ScreenUpdating = False
Dim FList As String, RList As String, i As Long
FList = "ZERO|ONE|TWO|THREE|FOUR|FIVE|SIX|SEVEN|EIGHT|NINE|TEN|ELEVEN|TWELVE"
RList = "CERO|UNO|DOS|TRES|CUATRO|CINCO|SEIS|SIETE|OCHO|NUEVE|DIEZ|ONCE|DOCE"
With ActiveDocument.Range.Find
.ClearFormatting
.Replacement.ClearFormatting
.Format = False
.Forward = True
.MatchCase = True
.MatchWholeWord = True
'Process each item from the Find/Replace Lists
For i = 0 To UBound(Split(FList, "|"))
.Text = Split(FList, "|")(i)
.Replacement.Text = Split(RList, "|")(i)
.Execute Replace:=wdReplaceAll
Next
End With
Application.ScreenUpdating = True
End Sub
just set .MatchWholeWord to true!
To process content in headers, footers, endnotes, footnotes, etc., as well as the document body, you would use code like:
Sub MultiFindReplaceEverywhere()
Application.ScreenUpdating = False
Dim Rng As Range, Sctn As Section, Shp As Shape, HdFt As HeaderFooter, h As Long
With ActiveDocument
For Each Rng In .StoryRanges
Call FndRep(Rng)
For Each Shp In Rng.ShapeRange
With Shp
If Not .TextFrame Is Nothing Then
Call FndRep(.TextFrame.TextRange)
End If
End With
Next
Next
For Each Sctn In .Sections
For Each HdFt In Sctn.Headers
With HdFt
If .Exists = True Then
If .LinkToPrevious = False Then
Call FndRep(HdFt.Range)
For Each Shp In HdFt.Shapes
With Shp
If Not .TextFrame Is Nothing Then
Call FndRep(.TextFrame.TextRange)
End If
End With
Next
End If
End If
End With
Next
For Each HdFt In Sctn.Footers
With HdFt
If .Exists = True Then
If .LinkToPrevious = False Then
Call FndRep(HdFt.Range)
For Each Shp In HdFt.Shapes
With Shp
If Not .TextFrame Is Nothing Then
Call FndRep(.TextFrame.TextRange)
End If
End With
Next
End If
End If
End With
Next
Next
End With
Options.DefaultHighlightColorIndex = h
Application.ScreenUpdating = True
End Sub
Sub FndRep(Rng As Range)
Dim FList As String, RList As String, i As Long
FList = "ZERO|ONE|TWO|THREE|FOUR|FIVE|SIX|SEVEN|EIGHT|NINE|TEN|ELEVEN|TWELVE"
RList = "CERO|UNO|DOS|TRES|CUATRO|CINCO|SEIS|SIETE|OCHO|NUEVE|DIEZ|ONCE|DOCE"
With Rng.Find
.ClearFormatting
.Replacement.ClearFormatting
.Format = False
.Forward = True
.MatchCase = True
.MatchWholeWord = True
'Process each item from the Find/Replace Lists
For i = 0 To UBound(Split(FList, "|"))
.Text = Split(FList, "|")(i)
.Replacement.Text = Split(RList, "|")(i)
.Execute Replace:=wdReplaceAll
Next
End With
End Sub
Related
The following code finds specific words and highlights them in Microsoft Word document. The code works perfectly fine. However when the code runs it doesn't highlight words inside text boxes. I need to highlight words in a regular paragraph and inside the text boxes. I've been messing around with it, however I cant figure it out. Any ideas you might have to do this?
Dim Word As range
Dim WordCollection(3) As String
Dim Words As Variant
'Define list.
'If you add or delete, change value above in Dim statement.
WordCollection(0) = "Hello World 1"
WordCollection(1) = "Hello World 2"
WordCollection(2) = "Hello World 3"
WordCollection(3) = "Hello World 4"
'Set highlight color.
Options.DefaultHighlightColorIndex = wdYellow
'Clear existing formatting and settings in Find feature.
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
'Set highlight to replace setting.
Selection.Find.Replacement.Highlight = True
'Cycle through document and find words in collection.
'Highlight words when found.
For Each Word In ActiveDocument.Words
For Each Words In WordCollection
With Selection.Find
.Text = Words
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Next
Next
End Sub
Code was found here
For a document-wide Find/Replace, you can use code like:
Sub Demo()
Application.ScreenUpdating = False
Dim Rng As Range, Sctn As Section, Shp As Shape, HdFt As HeaderFooter, h As Long
h = Options.DefaultHighlightColorIndex
Options.DefaultHighlightColorIndex = wdYellow
With ActiveDocument
For Each Rng In .StoryRanges
Call FndRep(Rng)
For Each Shp In Rng.ShapeRange
With Shp
If Not .TextFrame Is Nothing Then
Call FndRep(.TextFrame.TextRange)
End If
End With
Next
Next
For Each Sctn In .Sections
For Each HdFt In Sctn.Headers
With HdFt
If .Exists = True Then
If .LinkToPrevious = False Then
Call FndRep(HdFt.Range)
For Each Shp In HdFt.Shapes
With Shp
If Not .TextFrame Is Nothing Then
Call FndRep(.TextFrame.TextRange)
End If
End With
Next
End If
End If
End With
Next
For Each HdFt In Sctn.Footers
With HdFt
If .Exists = True Then
If .LinkToPrevious = False Then
Call FndRep(HdFt.Range)
For Each Shp In HdFt.Shapes
With Shp
If Not .TextFrame Is Nothing Then
Call FndRep(.TextFrame.TextRange)
End If
End With
Next
End If
End If
End With
Next
Next
End With
Options.DefaultHighlightColorIndex = h
Application.ScreenUpdating = True
End Sub
Sub FndRep(Rng As Range)
Dim Sctn As Section, h As Long, i As Long, ArrFnd(), ArrRep()
'Insert Find & Replace expressions here. The arrays must have the same # of entries
ArrFnd = Array("OldText 1", "OldText 2", "OldText 3", "OldText 4")
ArrRep = Array("NewText 1", "NewText 2", "NewText 3", "NewText 4")
With Rng.Find
.ClearFormatting
.Replacement.ClearFormatting
.Replacement.Highlight = True
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
For i = 0 To UBound(ArrFnd)
.Text = ArrFnd(i)
.Replacement.Text = ArrRep(i)
.Execute Replace:=wdReplaceAll
Next
End With
End Sub
Such code will process the document body, headers, footers, textboxes, footnotes, endnotes, etc. Superficially, one would expect to be able to loop through the document’s StoryRanges. However, the StoryRanges object doesn't work reliably with Find/Replace for headers, footers, & shapes - Find/Replace on a StoryRange with multiple header, footer, & shape members only ever seems to look at the first member.
For a Selection, you might use something like:
Sub Demo()
Application.ScreenUpdating = False
Dim Rng As Range, Shp As Shape, h As Long, i As Long, ArrFnd(), ArrRep()
ArrFnd = Array("Hello World 1", "Hello World 2", "Hello World 3", "Hello World 4")
ArrRep = Array("Goodbye All 1", "Goodbye All 2", "Goodbye All 3", "Goodbye All 4")
h = Options.DefaultHighlightColorIndex
Options.DefaultHighlightColorIndex = wdYellow
Set Rng = Selection.Range
For i = 0 To UBound(ArrFnd)
Call RngFndRep(Rng, ArrFnd(i), ArrRep(i))
Next
For Each Shp In Rng.ShapeRange
With Shp
If Not .TextFrame Is Nothing Then
For i = 0 To UBound(ArrFnd)
Call RngFndRep(.TextFrame.TextRange, ArrFnd(i), ArrRep(i))
Next
End If
End With
Next
Options.DefaultHighlightColorIndex = h
Application.ScreenUpdating = True
End Sub
Sub RngFndRep(Rng As Range, StrFnd, StrRep)
With Rng.Find
.ClearFormatting
.Replacement.ClearFormatting
.Replacement.Highlight = True
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.Text = StrFnd
.Replacement.Text = StrRep
.Execute Replace:=wdReplaceAll
End With
End Sub
I've used the following code to find and replace text on every storyrange, although I'm looking specifically for footers/headers and mainbody.
For Each myStoryRange In ActiveDocument.StoryRanges
If myStoryRange.StoryType = wdPrimaryFooterStory Then
myStoryRange.Find.Execute FindText:=footerfindreplace.Item(i).FND, Forward:=True, ReplaceWith:=footerfindreplace.Item(i).replc, Wrap:=wdFindContinue, replace:=wdReplaceAll
End If
If myStoryRange.StoryType = wdFirstPageFooterStory Then
myStoryRange.Find.Execute FindText:=footerfindreplace.Item(i).FND, Forward:=True, ReplaceWith:=footerfindreplace.Item(i).replc, Wrap:=wdFindContinue, replace:=wdReplaceAll
End If
If myStoryRange.StoryType = wdEvenPagesFooterStory Then
myStoryRange.Find.Execute FindText:=footerfindreplace.Item(i).FND, Forward:=True, ReplaceWith:=footerfindreplace.Item(i).replc, Wrap:=wdFindContinue, replace:=wdReplaceAll
End If
Next myStoryRange
It worked allright for the footers and if the document had only one section.
However I have documents with more than one section of course, and I'd rather go trough all the document. So I found a different approach:
With ActiveDocument
For Each Rng In .StoryRanges
On Error Resume Next
With Rng.Find
.ClearFormatting
.Replacement.ClearFormatting
.Format = False
.Forward = True
.Wrap = wdFindContinue
.Text = footerfindreplace.Item(i).FND
.Replacement.Text = footerfindreplace.Item(i).replc
.MatchCase = True
.Execute replace:=wdReplaceAll
End With
On Error GoTo 0
Next
For Each Sctn In .Sections
For Each HdFt In Sctn.Headers
With HdFt
If .LinkToPrevious = False Then
With .Range.Find
.ClearFormatting
.Replacement.ClearFormatting
.Format = False
.Forward = True
.Wrap = wdFindContinue
.Text = footerfindreplace.Item(i).FND
.Replacement.Text = footerfindreplace.Item(i).replc
.Execute replace:=wdReplaceAll
End With
End If
End With
Next
For Each HdFt In Sctn.Footers
With HdFt
If .LinkToPrevious = False Then
With .Range.Find
.ClearFormatting
.Replacement.ClearFormatting
.Format = False
.Forward = True
.Wrap = wdFindContinue
.Text = footerfindreplace.Item(i).FND
.Replacement.Text = footerfindreplace.Item(i).replc
.Execute replace:=wdReplaceAll
End With
End If
End With
Next
Next
End With
This works perfectly but has something I dislike, the word becomes unresponsive for about 10 seconds, regardless of the document. I also found there are 17 types of storyranges, and maybe that's the reason why it takes so long.
I know at least that with headers and footers (which are 6 of them) I can use the condition .Exists = true or false, to skip them. But that doesn't improve the result a lot.
I only have 5 words for replacement, Why does it become unresponsive? Is there a way to make it smooth?
Thanks for any help.
Update:
Upon reading the comments, I've tried the following with no avail
With ActiveDocument.StoryRanges(1).Find
.ClearFormatting
.Replacement.ClearFormatting
.Format = False
.Forward = True
.Wrap = wdFindContinue
.Text = footerfindreplace.Item(i).FND
.Replacement.Text = footerfindreplace.Item(i).replc
.MatchCase = True
.MatchAllWordForms = False
.MatchWholeWord = False
.MatchWildcards = False
End With
For Each Rng In ActiveDocument.StoryRanges
On Error Resume Next
With Rng.Find
.Text = footerfindreplace.Item(i).FND
.Replacement.Text = footerfindreplace.Item(i).replc
.Execute replace:=wdReplaceAll
End With
On Error GoTo 0
Next
For Each Sctn In ActiveDocument.Sections
For Each HdFt In Sctn.Headers
With HdFt
If .LinkToPrevious = False Then
If HdFt.Exists = True Then
With .Range.Find
.Text = footerfindreplace.Item(i).FND
.Replacement.Text = footerfindreplace.Item(i).replc
.Execute replace:=wdReplaceAll
End With
End If
End If
End With
Next
For Each HdFt In Sctn.Footers
With HdFt
If .LinkToPrevious = False Then
If HdFt.Exists = True Then
With .Range.Find
.Text = footerfindreplace.Item(i).FND
.Replacement.Text = footerfindreplace.Item(i).replc
.Execute replace:=wdReplaceAll
End With
End If
End If
End With
Next
Next
If I dont place
.Text = footerfindreplace.Item(i).FND
.Replacement.Text = footerfindreplace.Item(i).replc
In every loop, it will not replace. Also the update display is already false.
Can anyone help?
Update:
Recently I tried to search every section inside mystory ranges, hoping to filter out the order..
For Each storyrang In ActiveDocument.StoryRanges
For Each Sctn In storyrang.Sections
For Each rang In Sctn.Ranges
With rang
For ii = 1 To footerfindreplace.count
Call RngFnd(.Range, footerfindreplace.Item(i).FND, footerfindreplace.Item(i).replc) 'find and replace text in the given range
Next ii
End With
Next
Next
Next
The result however remains not good
Your code is lacking context - specifically regarding footerfindreplace.Item(i).FND and footerfindreplace.Item(i).replc. You're code is also processing all storyranges (which includes headers & footers), then processing headers & footers again by Section.
If footerfindreplace.Item(i).FND and footerfindreplace.Item(i).replc represent a single call to the document, you might use code like:
Sub Demo()
Application.ScreenUpdating = False
Dim Sctn As Section, HdFt As HeaderFooter
With ActiveDocument
Call RngFnd(.Range, footerfindreplace.Item(i).FND, footerfindreplace.Item(i).replc)
For Each Sctn In .Sections
For Each HdFt In Sctn.Headers
With HdFt
If .LinkToPrevious = False Then
Call RngFnd(.Range, footerfindreplace.Item(i).FND, footerfindreplace.Item(i).replc)
End If
End With
Next
For Each HdFt In Sctn.Footers
With HdFt
If .LinkToPrevious = False Then
Call RngFnd(.Range, footerfindreplace(i).FND, footerfindreplace(i).replc)
End If
End With
Next
Next
End With
Application.ScreenUpdating = True
End Sub
Sub RngFnd(Rng As Range, StrFnd As String, StrRep As String)
With Rng.Find
.ClearFormatting
.Replacement.ClearFormatting
.Format = False
.Forward = True
.Wrap = wdFindContinue
.Text = StrFnd
.Replacement.Text = StrRep
.MatchCase = True
.Execute Replace:=wdReplaceAll
End With
End Sub
Alternatively, if you're processing multiple footerfindreplace items, you might use code like:
Sub Demo()
Application.ScreenUpdating = False
Dim Sctn As Section, HdFt As HeaderFooter
With ActiveDocument
Call RngFnd(.Range, footerfindreplace)
For Each Sctn In .Sections
For Each HdFt In Sctn.Headers
With HdFt
If .LinkToPrevious = False Then
Call RngFnd(.Range, footerfindreplace)
End If
End With
Next
For Each HdFt In Sctn.Footers
With HdFt
If .LinkToPrevious = False Then
Call RngFnd(.Range, footerfindreplace)
End If
End With
Next
Next
End With
Application.ScreenUpdating = True
End Sub
Sub RngFnd(Rng As Range, ArrFndRep)
Dim i As Long
With Rng.Find
.ClearFormatting
.Replacement.ClearFormatting
.Format = False
.Forward = True
.MatchCase = True
.Wrap = wdFindContinue
For i = 0 To UBound(ArrFndRep)
.Text = ArrFndRep(i).FND
.Replacement.Text = ArrFndRep(i).replc
.Execute Replace:=wdReplaceAll
Next
End With
End Sub
In either case, though, it's hardly apparent why you'd be processing something described as footerfindreplace in either the document body or its headers...
I'm posting this years later in case it helps others coding for StoryRanges.
I've got a similar issue and the OP's code gave me a start, so this is my Thank you.
The OP wanted to replace arbitrary text in MainTextStory, and in all Headers & Footers. His original code failed if there was more than a single Section.
The vital element is that Help defines StoryRanges as a Collection of Ranges.
Story Ranges can be chained together by the NextStoryRange property
This code iterates the entire document text just once
The Find Replace is the OP's code, but I've added a For loop for clarity
For Each myStoryRange In ActiveDocument.StoryRanges
Do
For i = lbound(footerfindreplace.Item) to Ubound(footerfindreplace.Item)
myStoryRange.Find.Execute FindText:=footerfindreplace.Item(i).FND, Forward:=True, ReplaceWith:=footerfindreplace.Item(i).replc, Wrap:=wdFindContinue, Replace:=wdReplaceAll
next i
If Not myStoryRange.NextStoryRange Is Nothing Then
Set myStoryRange = myStoryRange.NextStoryRange
End If
Loop Until myStoryRange.NextStoryRange Is Nothing
Next MyStoryRange
I hope this helps somebody at some time
Spilly
How can I delete the text between <de> and the end-of-cell marker throughout my Word document?
I have reached the following code from my previous question. It appeared not to be working because my lines end with end-of-cell markers. So now I need to update this to delete the text between <de>and the end-of-cell marker.
I am unable to implement that in this code.
Sub FindTheDeleteToEndOfLine()
Dim searchTerm As String
Dim bFound As Boolean
searchTerm = "<de>"
Selection.HomeKey wdStory
'Basic Find settings
With Selection.Find
.Forward = True
.wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
'Execute the Find
Do
With Selection.Find
.Text = searchTerm
bFound = .Execute
If bFound Then
Selection.MoveEnd wdLine, 1
Selection.MoveEnd wdCharacter, -1
Selection.Delete
End If
End With
Loop While bFound
End Sub
Update: I worked out a new code less complicated, but again i am unale to define the arng.words in order to delete last part after <de>:
Dim arng As Range
Dim i As Long, j As Long
With Selection.Tables(1)
For i = 1 To .Rows.Count
For j = 1 To .Columns.Count
Set arng = .Cell(i, j).Range
arng.End = arng.End - 1
'Text = "<de>"
If Right(arng.Words, 1) = "<de>" Then
arng.Words.Last = Left(arng.Words, Len(arng.Words) - 1)
End If
Next j
Next i
End With
Try, for example:
Sub Demo()
Application.ScreenUpdating = False
With ActiveDocument.Range
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "<de>"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute
End With
Do While .Find.Found
If .Information(wdWithInTable) = True Then
.End = .Cells(1).Range.End - 1
.Delete
End If
.Collapse wdCollapseEnd
.Find.Execute
Loop
End With
Application.ScreenUpdating = True
End Sub
The problem you're encountering here is due to how Word reacts to a selection inside a cell: as soon as it reaches the end of the cell it selects the entire cell.
I've modified the code (which makes it more "complicated") to take this into account. In order to deal with this, there is now a Range object in the code that stores the original "Found" point in the document. After extending the selection to the end of the line, and moving it back one character (which means the entire cell is selected), the starting point is re-set to the "found" position.
Sub FindTheDeleteToEndOfCell()
Dim searchTerm As String
Dim bFound As Boolean
Dim rngFound As Word.Range
searchTerm = "<de>"
Selection.HomeKey wdStory
'Basic Find settings
With Selection.Find
.Forward = True
.wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
'Execute the Find
Do
With Selection.Find
.Text = searchTerm
bFound = .Execute
If bFound Then
Set rngFound = Selection.Range
Selection.MoveEnd wdLine, 1
Selection.MoveEnd wdCharacter, -1
Selection.Start = rngFound.Start
Selection.Delete
End If
End With
Loop While bFound
End Sub
I'm trying to find a regex string, <XE "i#>, in a Word document.
Background: I'm building an index, and automatically picking up paragraphs to add via another macro. There are some entries that start "i. Automobile - means a car", or "ii. Super - means really good". I want to remove the numbering part from the Index entry, so thought a way to do so would be to look for the {XE "i. Automobile ...} part and just remove the i. using RegEx.
When I search manually for my string, it works fine and picks up the matches. However, my macro doesn't work. When stepping through, then I get to While .Execute, the next step just goes to Wend then End With. It does ask if I want to search from the beginning, so the .Find is working somewhat, but why isn't it finding any matches?
Thanks so much for any advice!
Sub Hide_Roman_Numerals_from_Index()
Dim defText As String
Dim regExSearch As String
Dim oRng As Word.Range, rng As Word.Range
If ActiveWindow.ActivePane.View.ShowAll = False Then
ActiveWindow.ActivePane.View.ShowAll = True
End If
Set oRng = ActiveDocument.Range
'Call ClearFindAndReplaceParameters(oRng)
regExSearch = "<XE ""i#>"
oRng.Find.ClearFormatting
With oRng.Find
.Text = regExSearch
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
While .Execute
Set rng = oRng.Paragraphs(1).Range
rng.Select
Wend
End With
If ActiveWindow.ActivePane.View.ShowAll = True Then
ActiveWindow.ActivePane.View.ShowAll = False
End If
'Call ClearFindAndReplaceParameters(oRng)
End Sub
I think this approach will suit you if I got your problem right.
'BruceWayne
Sub Colorgreenfromw()
Application.ScreenUpdating = False
Dim oPar As Paragraph
Dim oRng As Word.Range
For Each oPar In ActiveDocument.Paragraphs
Set oRng = oPar.Range
With oRng
With .Find
.ClearFormatting
.Font.Color = wdColorGreen
.Replacement.ClearFormatting
.Text = "<XE ""i#>"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchWildcards = True
.Execute
End With
If .Find.Found Then
Set oRng = oPar.Range
oRng.Font.Color = wdColorGreen
Set oRng = Nothing
End If
End With
Next
End Sub
Code to highlight italic text:
Sub Bold_Italic()
Dim rng As Range
Set rng = ActiveDocument.Range
rng.Collapse Direction:=wdCollapseStart
rng.Find.ClearFormatting
rng.Find.Font.Italic = True
rng.Find.Replacement.ClearFormatting
rng.Find.Replacement.Highlight = True
rng.Find.Replacement.Font.Color = wdColorRed
With rng.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
rng.Find.Execute Replace:=wdReplaceAll
End Sub
How can i highlight the whole paragraph or make selected for a paragraph?
Actually, i want to copy and paste paragraph by paragraph to another document.
I believe you're looking for range.select
Sub Macro()
Dim i As Integer
For i = 1 To ActiveDocument.Paragraphs.Count
Dim range As range
Set range = ActiveDocument.Paragraphs(i).range
'range.Characters.Count > 1 means there is text in the paragraph
If range.Characters.Count > 1 Then
'Handle the desired operation with the paragraph text
range.Select
MsgBox (range.Text)
End If
Next i
End Sub