View Single Post
 
Old 11-23-2023, 05:16 AM
gmaxey gmaxey is offline Windows 10 Office 2019
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,601
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

What specifically are you trying to do? If you want to insert a line break before " (about" then:


Code:
Sub ScratchMacro()
'A basic Word Macro coded by Gregory K. Maxey
Dim oRng As Range
  Set oRng = ActiveDocument.Range
  With oRng.Find
    .Text = " (about"
    If .Execute Then
      oRng.Characters(1).Delete
      oRng.InsertBefore Chr(11)
    End If
  End With
lbl_Exit:
  Exit Sub
End Sub

In your existing code, the .Execute is only going return True once because after the first find, oRng IS the found text and the found text is the text you want to find.



Type this sentence in a select a word document and then run:


Code:
Sub Demo()
Dim oRng As Range
  Set oRng = Selection.Range
  With oRng.Find
    .Text = Selection.Text
    If .Execute Then
      MsgBox "Found"
    Else
      MsgBox "I can't find myself when I AM the defined search range."
    End If
  End With
lbl_Exit:
  Exit Sub
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote