View Single Post
 
Old 10-17-2019, 08:17 AM
gmaxey gmaxey is offline Windows 10 Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,598
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

Code:
Sub Converttoheadingstyle()
Dim oPara As Paragraph
Dim oRng As Range
Dim oParRng As Range
Dim lngCount As Long

  If Selection.Type = wdSelectionNormal Then: Set oRng = Selection.Range: Else: Set oRng = ActiveDocument.Range
  For Each oPara In oRng.Paragraphs
    lngCount = 0
    Set oParRng = oPara.Range.Duplicate
    If IsNumeric(oParRng.Characters(1)) Then
      oParRng.Collapse wdCollapseStart
      Do
        oParRng.Move wdCharacter, 1
        If oParRng.Characters.Last = "." Then lngCount = lngCount + 1
        If Not IsNumeric(oParRng.Characters.Last) And oParRng.Characters.Last <> "." Then Exit Do
      Loop
      oPara.Style = ActiveDocument.Styles("Heading " & lngCount): oParRng.Text = ""
    End If
  Next oPara
lbl_Exit:
  Exit Sub
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote