View Single Post
 
Old 10-01-2024, 05:22 AM
gmaxey gmaxey is offline Windows 10 Office 2019
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,617
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

Shelly, your examples (almost verbatim) is included in the file that I uploaded with my last reply. The previous code worked fine.



The following code is modified to handle one or more spaces in a similar circumstance:

Code:
Option Explicit
Private oRngNum As Range
Sub FormatManualNumbering()
Dim oRng As Range
Dim oPar As Paragraph
    Application.ScreenUpdating = False
    Set oRng = ActiveDocument.Range
    oRng.InsertBefore vbCr
    With oRng.Find
      .ClearFormatting
      .Replacement.ClearFormatting
      .Forward = True
      .Wrap = wdFindStop
      .Format = False
      .MatchWildcards = False
      'Remove spaces starting paras:
      .Text = "^p^w"
      .Replacement.Text = "^p"
      .Execute Replace:=wdReplaceAll
    End With
    oRng.Characters(1).Delete
    For Each oPar In oRng.Paragraphs
      If IsNumeric(oPar.Range.Characters(1)) Then
        Set oRngNum = oPar.Range
        oRngNum.Collapse wdCollapseStart
        Do Until oRngNum.Characters.Last.Next Like "[A-Za-z]"
          oRngNum.MoveEnd wdCharacter, 1
        Loop
        ProcessNum
      End If
    Next
   Application.ScreenUpdating = True
lbl_Exit:
  Exit Sub
End Sub
Sub ProcessNum()
Dim oRng As Range
Dim lngIndex As Long
Dim bAllNums As Boolean
  bAllNums = True
  Set oRng = oRngNum.Duplicate
  oRng.Collapse wdCollapseEnd
  Do Until IsNumeric(oRng.Characters.First.Previous)
    oRng.MoveStart wdCharacter, -1
  Loop
  oRng.Text = "." & vbTab
  oRngNum.End = oRng.Start
  For lngIndex = oRngNum.Characters.Count To 1 Step -1
    If Not IsNumeric(oRngNum.Characters(lngIndex)) Then
      oRngNum.Characters(lngIndex).Select
      If oRngNum.Characters(lngIndex) = " " And oRngNum.Characters(lngIndex).Previous = "." _
         Or oRngNum.Characters(lngIndex).Previous = " " Then
        oRngNum.Characters(lngIndex).Delete
      Else
        oRngNum.Characters(lngIndex) = "."
        bAllNums = False
      End If
    End If
  Next
  If Not bAllNums Then oRngNum.Characters.Last.Next.Delete
lbl_Exit:
  Exit Sub
End Sub

If this is still not working, then please upload and example file.
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote