![]() |
#36
|
|||
|
|||
![]()
Hi Greg, its a bit baffling that it works on your PC but not mine. I've been trying to get the code to work on my PC but to no avail, not even with .docm file, so I've gone back to your original code and have modified it slightly (see red in code) to do what I need it to do and seems to be working so far.
Thanks for all your help on this Greg, it is very much appreciated as always. The code really is awesome. Best, Shelley Code:
Private oRngNum As Range Sub DPU_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 'Remove empty paras: .MatchWildcards = True .text = "^13{2,}" .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 Set oRng = ActiveDocument.Range With oRng.Find .MatchWildcards = True .text = "([0-9]).." .Replacement.text = "\1." .Execute Replace:=wdReplaceAll End With 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 oRngNum.Characters(lngIndex) = "." bAllNums = False End If Next If Not bAllNums Then oRngNum.Characters.Last.Next.Delete lbl_Exit: Exit Sub End Sub |
|
![]() |
||||
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 |