Thread: [Solved] Macro to number sentences
View Single Post
 
Old 02-16-2017, 01:42 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
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
Dim i As Long, Rng As Range
With ActiveDocument.Range
  For i = 1 To .Sentences.Count
    With .Sentences(i)
      .InsertBefore " "
      Set Rng = .Characters.First
      Rng.Collapse wdCollapseStart
      .Fields.Add Range:=Rng, Type:=wdFieldSequence, _
        Text:="No.", PreserveFormatting:=False
    End With
  Next
End With
Set Rng = Nothing
Application.ScreenUpdating = True
End Sub
With this code, the numbering is applied via SEQ fields. Had I hard-coded the numbers, you would have had to re-number every sentence after the first one that gets mis-numbered; this way simply deleting the offending numbers then updating the fields (e.g. Ctrl-A, F9) - which you can leave till all the offending numbers have been deleted - is all you need do.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote