View Single Post
 
Old 02-06-2020, 05:58 PM
macropod's Avatar
macropod macropod is online now Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,387
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Another way of automatically swapping the word order, sticking to the 'within characters' approach:
Code:
Sub Demo()
Application.ScreenUpdating = False
Dim i As Long, j As Long, StrFnd As String
StrFnd = InputBox("Please input the Find paramenters, as:" & vbCr & _
  "word1|word2|x,y" & vbCr & _
  "where:" & vbCr & _
  "'x' is the minimum intervening character count and" & vbCr & _
  "'y' is the maximum intervening character count.")
For i = 1 To 2
  With ActiveDocument.Range
    With .Find
      .ClearFormatting
      .Replacement.ClearFormatting
      .Text = "<" & Split(StrFnd, "|")(1 - i Mod 2) & ">?{" & Split(StrFnd, "|")(2) & "}<" & Split(StrFnd, "|")(2 - i) & ">"
      .Replacement.Text = ""
      .Forward = True
      .Format = False
      .Wrap = wdFindStop
      .MatchWildcards = True
      .Execute
    End With
    Do While .Find.Found
      j = j + 1
      .Collapse wdCollapseEnd
      .Find.Execute
    Loop
  End With
Next
Application.ScreenUpdating = True
MsgBox j & " instances found."
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote