dagerr
03-23-2018, 01:22 PM
Hi,
The following code change next paragraph if searched word is founded. I want modify code to continue macro if paragraph after finding searched word not exist or founded word is last in document.
Thanks
Dim oRng As Range
Set oRng = ActiveDocument.Range
With oRng.Find
Do While .Execute(FindText:="FOTO", MatchWholeWord:=True)
oRng.End = oRng.Paragraphs(1).Range.End
oRng.Collapse
'if praragraph not exist??
If (oRng.End = oRng.Next.Paragraphs(1).Range.End) = False Then
Exit Sub
Else
End If
oRng.End = oRng.Next.Paragraphs(1).Range.End
If Len(oRng) = 1 Then
oRng.Collapse 0
oRng.End = oRng.Next.Paragraphs(1).Range.End
End If
With oRng
.Font.Name = "Times New Roman"
.Font.Size = 8
.Font.Italic = wdToggle
.bold = False
With .ParagraphFormat
.LeftIndent = CentimetersToPoints(0)
.RightIndent = CentimetersToPoints(0)
.SpaceBefore = 0
.SpaceBeforeAuto = False
.SpaceAfter = 10
.SpaceAfterAuto = False
.LineSpacingRule = wdLineSpaceMultiple
.LineSpacing = LinesToPoints(0.9)
.Alignment = wdAlignParagraphLeft
.WidowControl = True
.KeepWithNext = False
.KeepTogether = False
.PageBreakBefore = False
.NoLineNumber = False
.Hyphenation = True
.FirstLineIndent = CentimetersToPoints(0)
.OutlineLevel = wdOutlineLevelBodyText
.CharacterUnitLeftIndent = 0
.CharacterUnitRightIndent = 0
.CharacterUnitFirstLineIndent = 0
.LineUnitBefore = 0
.LineUnitAfter = 0
.MirrorIndents = False
.TextboxTightWrap = wdTightNone
End With
.Collapse 0
End With
Loop
End With
lbl_Exit:
Set oRng = Nothing
The following code change next paragraph if searched word is founded. I want modify code to continue macro if paragraph after finding searched word not exist or founded word is last in document.
Thanks
Dim oRng As Range
Set oRng = ActiveDocument.Range
With oRng.Find
Do While .Execute(FindText:="FOTO", MatchWholeWord:=True)
oRng.End = oRng.Paragraphs(1).Range.End
oRng.Collapse
'if praragraph not exist??
If (oRng.End = oRng.Next.Paragraphs(1).Range.End) = False Then
Exit Sub
Else
End If
oRng.End = oRng.Next.Paragraphs(1).Range.End
If Len(oRng) = 1 Then
oRng.Collapse 0
oRng.End = oRng.Next.Paragraphs(1).Range.End
End If
With oRng
.Font.Name = "Times New Roman"
.Font.Size = 8
.Font.Italic = wdToggle
.bold = False
With .ParagraphFormat
.LeftIndent = CentimetersToPoints(0)
.RightIndent = CentimetersToPoints(0)
.SpaceBefore = 0
.SpaceBeforeAuto = False
.SpaceAfter = 10
.SpaceAfterAuto = False
.LineSpacingRule = wdLineSpaceMultiple
.LineSpacing = LinesToPoints(0.9)
.Alignment = wdAlignParagraphLeft
.WidowControl = True
.KeepWithNext = False
.KeepTogether = False
.PageBreakBefore = False
.NoLineNumber = False
.Hyphenation = True
.FirstLineIndent = CentimetersToPoints(0)
.OutlineLevel = wdOutlineLevelBodyText
.CharacterUnitLeftIndent = 0
.CharacterUnitRightIndent = 0
.CharacterUnitFirstLineIndent = 0
.LineUnitBefore = 0
.LineUnitAfter = 0
.MirrorIndents = False
.TextboxTightWrap = wdTightNone
End With
.Collapse 0
End With
Loop
End With
lbl_Exit:
Set oRng = Nothing