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