View Single Post
 
Old 02-28-2014, 10:38 PM
macropod's Avatar
macropod macropod is offline Windows 7 32bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
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

Quote:
Originally Posted by dgp View Post
Can we control the insertion of tag before the period('.') ?
In what sense? Do you want the tag before the period, or after, as it is now? On the assumption you want the tags before the period (etc.), try:
Code:
Sub Demo()
Application.ScreenUpdating = False
Dim ArrFnd, i As Long, wdDoc As Document
Set wdDoc = ActiveDocument
wdDoc.ActiveWindow.View.ShowFieldCodes = True
ArrFnd = Array("must", "shall")
For i = 0 To UBound(ArrFnd)
  Call TagIt(wdDoc, ArrFnd(i), "R")
Next
ArrFnd = Array("may", "should")
For i = 0 To UBound(ArrFnd)
  Call TagIt(wdDoc, ArrFnd(i), "M")
Next
With wdDoc
  .Fields.Update
  .ActiveWindow.View.ShowFieldCodes = False
End With
Application.ScreenUpdating = True
End Sub
 
Sub TagIt(wdDoc As Document, strFnd As Variant, strTag As String)
Dim RngTag As Range
  With wdDoc.Range
    With .Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = strFnd
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindStop
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    .Execute
    End With
    Do While .Find.Found
      Set RngTag = .Duplicate
      With RngTag
        .End = .Sentences.First.End - 2
        While Not .Characters.Last.Next.Text Like "[.!?]"
          .End = .End - 1
        Wend
        While (.Characters.Last = Chr(19)) Or (.Characters.Last = Chr(23))
          .End = .End - 1
        Wend
        .Collapse wdCollapseEnd
      End With
      .Fields.Add RngTag, wdFieldEmpty, "SEQ " & strTag & " \# '[" & strTag & "'000']'", False
      .Collapse wdCollapseEnd
      .Find.Execute
    Loop
  End With
End Sub
Note the re-structured code.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote