Thread: select until =
View Single Post
 
Old 01-30-2024, 09:46 AM
vivka vivka is offline Windows 7 64bit Office 2016
Expert
 
Join Date: Jul 2023
Posts: 302
vivka is on a distinguished road
Default

Yes, Greg, your code is quite interesting! I tried to avoid the selection but couldn't. I've only added two short lines to your code (without them it didn't fulfill its task):
Code:
Sub Test_Macro()
'Copy a range from the current para's start till after "=" and
'paste it after the para.

Dim oRng As range

  Set oRng = selection.Paragraphs(1).range
  oRng.Copy
  selection.Find.ClearFormatting
  selection.Find.Replacement.ClearFormatting
  With oRng.Find
    .text = "="
    .Forward = True
    .Wrap = wdFindStop
    .Format = False
    If .Execute Then
      oRng.InsertAfter vbCr
      oRng.Paragraphs(1).Next.range.FormattedText = oRng.Paragraphs(1).range.FormattedText
      oRng.Paragraphs(1).range.PasteAndFormat (wdFormatOriginalFormatting)
    End If
  End With
lbl_Exit:
  Exit Sub
End Sub
Reply With Quote