Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #4  
Old 10-17-2019, 01:09 PM
gmaxey gmaxey is offline Count number of periods and convert paragraph to a heading style Windows 10 Count number of periods and convert paragraph to a heading style Office 2016
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

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.MoveEnd wdCharacter, 1
        If oParRng.Characters.Last = "." Then lngCount = lngCount + 1
        oParRng.Select
        If Not IsNumeric(oParRng.Characters.Last) And oParRng.Characters.Last <> "." Then Exit Do
      Loop
      oPara.Style = ActiveDocument.Styles("Heading " & lngCount)
      oParRng.End = oParRng.End - 1
      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
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Can I create a page number from a non-Heading style? techwriter3k Word 9 09-25-2019 06:58 AM
Phone Number Replace ( ) and - with periods (I'm ALMOST there) trikky Mail Merge 4 07-19-2019 04:03 PM
Count number of periods and convert paragraph to a heading style applying heading style within paragraph using macro cheech1981 Word 8 08-23-2017 03:07 PM
Count number of periods and convert paragraph to a heading style Heading style is not showing paragraph "before spacing" on second page Dave_K Word 1 07-02-2014 12:06 AM
Count number of periods and convert paragraph to a heading style Using heading style level in a paragraph kam Word 7 03-24-2014 02:58 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:42 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft