![]() |
|
#1
|
|||
|
|||
![]()
Shelly,
We have better things to do than look for needles in haystacks. Can you please indicate what is wrong in the After.docx after the code is run. 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 = 1 To oRngNum.Characters.Count If Not IsNumeric(oRngNum.Characters(lngIndex)) Then If oRngNum.Characters(lngIndex) = " " And oRngNum.Characters(lngIndex).Previous = "." Then oRngNum.Characters(lngIndex).Delete lngIndex = lngIndex + 1 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 |
#2
|
|||
|
|||
![]()
Hi Greg, I have updated a previous post with before, after and what it should do/end result - it looks like its still the double period issue.
|
#3
|
|||
|
|||
![]()
Hi Greg, on the whole the code works as it should and I'm really grateful for your time - the only issue is that where there is a period followed by a space (see 1.2 and 1.3.1 in the first image), the code is adding an additional period but is removing the space (see second image).
Before code is run Manual numbering should be separated by periods and no spaces inbetween. Before.JPG After the code has run Where there is a period followed by a space (see 1.2 and 1.3.1 in first image), the code adds an additional period but does remove the space. After.JPG This is what the text should look like when the code has run, no double periods. What it should look like.jpg |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
Shelley Lou | Word VBA | 1 | 03-05-2023 03:45 AM |
![]() |
Shelley Lou | Word VBA | 2 | 08-04-2021 12:24 AM |
![]() |
Shelley Lou | Word VBA | 8 | 05-28-2021 01:08 AM |
![]() |
stanley | Word | 4 | 12-15-2020 10:59 AM |
page numbering for manual | Bursal | Word | 1 | 07-29-2018 02:08 PM |