Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 09-22-2021, 02:12 PM
Shelley Lou Shelley Lou is offline VBA help with auto numbering Windows 10 VBA help with auto numbering Office 2016
Competent Performer
VBA help with auto numbering
 
Join Date: Dec 2020
Posts: 170
Shelley Lou is on a distinguished road
Default VBA help with auto numbering

Hi, when converting pdfs to Word, text is pasted as unformatted which then generates manual numbering. I found a brilliant bit of code from Macropod which changes any digits to the correct Heading style, except where letters/numbers are within parentheses e.g. (a) lowercase becomes Heading 3 (1.1.1), (i) roman numeral becomes Heading 4 (1.1.1.1), (A) uppercase becomes Heading 5 (a) and (1) Arabic becomes Heading 6 (i).



The code also needs to say that if the numbering is either Heading NUM (which represents the parties as (1), (2) etc. and Heading CHR which represents the Recitals AS (A), (B) etc. the code should not change these styles.


I have some code that converts manual numbering to auto within a table for definitions and I thought I could merge some of this code into Macropod's code but nothing seems to be working and I have no idea what i = Asc(Split(Split(.Text, "(")(1), ")")(0)) means.

Can anyone help?, thanks, Shelley

Test Doc to convert manual numbering to auto numbering.docx

Macropod's Code

Code:
Sub DPU_ManualToAuto_NewNumbering_ExcTables()
Application.ScreenUpdating = False
Dim Para As Paragraph, Rng As Range, iLvl As Long
With ActiveDocument.Range
  For Each Para In .Paragraphs
    If Para.Range.Information(wdWithInTable) = False Then
      Set Rng = Para.Range.Words.First
      With Rng
        If IsNumeric(.Text) Then
          While .Characters.Last.Next.Text Like "[0-9. " & vbTab & "]"
            .End = .End + 1
          Wend
          iLvl = UBound(Split(.Text, "."))
          If IsNumeric(Split(.Text, ".")(UBound(Split(.Text, ".")))) Then iLvl = iLvl + 1
          If iLvl < 10 Then
            .Text = vbNullString
            Para.Style = "Heading " & iLvl
          End If
        End If
      End With
    End If
  Next
End With
Application.ScreenUpdating = True
End Sub
Definitions Table Code

Code:
Sub DPU_ApplyTableStyles()
Application.ScreenUpdating = False
Dim r As Long, i As Long
With ActiveDocument.Tables(1)
  For r = 1 To .Rows.Count
    With .Cell(r, 2).Range
      If .Characters.First <> "(" Then
        .Style = "Definition Level 1"
      Else
        i = Asc(Split(Split(.Text, "(")(1), ")")(0))
        Select Case i
          Case 97 To 104, 106 To 117, 119, 121 To 122: .Style = "Definition Level 2" 'LowercaseLetter
          Case 65 To 90: .Style = "Definition Level 4" 'UppercaseLetter
          Case 48 To 57: .Style = "Definition Level 5" 'Arabic
          Case 105, 118, 120: .Style = "Definition Level 3" 'LowercaseRoman
        End Select
        .Collapse wdCollapseStart
        .MoveEndUntil " "
        .End = .End + 1
        .Delete
      End If
    End With
  Next
End With
Application.ScreenUpdating = True
End Sub
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA help with auto numbering VBA converting manual numbering to auto numbering Shelley Lou Word VBA 8 05-28-2021 01:08 AM
Auto numbering of custom text Piet200 Word 1 11-18-2020 06:38 AM
Auto numbering macro desireemm1 Word 1 12-10-2015 07:50 PM
Mail Merge Auto Numbering MaxBuck Mail Merge 5 02-19-2013 08:13 PM
VBA help with auto numbering auto page numbering socomfort Word 2 05-28-2012 04:19 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:03 PM.


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