Thread: [Solved] word 2013 operation on text
View Single Post
 
Old 09-26-2018, 06:35 AM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
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

Try:
Code:
Sub Demo()
Application.ScreenUpdating = False
With ActiveDocument.Range
  With .Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = "<[0-9]{1,4}>?????"
    .Replacement.Text = ""
    .Forward = True
    .Format = False
    .Wrap = wdFindStop
    .MatchWildcards = True
    .Execute
  End With
  Do While .Find.Found
    If InStr(.Text, " ") > 0 Then
      Select Case Split(.Text, " ")(1)
        Case "B.C."
          .Text = .Text & " (chinese year " & Split(.Text, " ")(0) + 2699 & ")"
        Case "A.D."
          .Text = .Text & " (chinese year " & Split(.Text, " ")(0) + 2698 & ")"
        Case Else
          .End = .Words.First.End
          .Text = .Text & " (chinese year " & .Text + 2698 & ")"
      End Select
    Else
      .End = .Words.First.End
      .Text = .Text & " (chinese year " & .Text + 2698 & ")"
    End If
    .Collapse wdCollapseEnd
    .Find.Execute
  Loop
End With
Application.ScreenUpdating = True
End Sub
Do note, however, that the code will now insert the text after any 4-digit number; numbers of other lengths will be ignored.

PS: Please give the magenta a rest...
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote