Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-06-2024, 08:41 AM
vivka vivka is offline VBA Format manual numbering so auto numbering code can run Windows 7 64bit VBA Format manual numbering so auto numbering code can run Office 2016
Expert
 
Join Date: Jul 2023
Posts: 305
vivka is on a distinguished road
Default

Hi, Shelley Lou! You can change your code to
Code:
.text = "^13[!^13]@[^t ]"
But this may bring about new problems because spaces are everywhere in the text including between numbers in multi-level lists (e.g.: 2 2.2tabfolllowing a written...). As a remedy, I would replace all digit-letter spaces with tabs and then run the original code. Or, please, post a new (more complex, including as many numbering cases as possible) sample of your doc to try different code changes on.
Reply With Quote
  #2  
Old 08-06-2024, 08:48 AM
Shelley Lou Shelley Lou is offline VBA Format manual numbering so auto numbering code can run Windows 10 VBA Format manual numbering so auto numbering code can run Office 2016
Expert
VBA Format manual numbering so auto numbering code can run
 
Join Date: Dec 2020
Posts: 259
Shelley Lou is on a distinguished road
Default VBA Format manual numbering so auto numbering code can run

Hi Vivka, yes I did try that variation but it didn't work for me. I've attached an updated test document so you can see what I mean with regard to the spaces - not sure how to get around this.

format manual numbering before running auto numbering code.docx
Reply With Quote
  #3  
Old 08-06-2024, 10:49 AM
vivka vivka is offline VBA Format manual numbering so auto numbering code can run Windows 7 64bit VBA Format manual numbering so auto numbering code can run Office 2016
Expert
 
Join Date: Jul 2023
Posts: 305
vivka is on a distinguished road
Default

Hi again, Shelley Lou! I think we did it at last! The code has bloated but it works properly in (as I think) all possible cases (see the attached test doc modified by me).

Code:
Sub FormatManualNumbering()
'In active doc, format multi-level manual numbering.

Dim rng As range
Dim rngEnd As Long

Application.ScreenUpdating = False
    Set rng = ActiveDocument.range
    rngEnd = rng.End
    rng.Characters.First.InsertBefore Chr(13)
    With rng.Find
        .ClearFormatting
        .Replacement.ClearFormatting
        .Forward = True
        .Wrap = wdFindStop
        .Format = True
        .MatchWildcards = True
        .text = "(^13[!^13]@)([A-Za-z])"
        .Replacement.text = "\1^t\2"
        .Execute Replace:=wdReplaceAll
        .text = "^t^t"
        .Replacement.text = "^t"
        .Execute Replace:=wdReplaceAll
    End With
    Do
        With rng.Find
            .ClearFormatting
            .Replacement.ClearFormatting
            .Forward = True
            .Wrap = wdFindStop
            .Format = True
            .MatchWildcards = True
            .text = "^13[!^13]@^t"
            If .Execute And rng.End <= rngEnd Then
                .text = "[,:; ]"
                .Replacement.text = "."
                .Execute Replace:=wdReplaceAll
            Else: Exit Do
            End If
            If rng.Characters.Last.Previous = "." Then
                rng.Characters.Last.Previous.Delete
            End If
            rng.Collapse wdCollapseEnd
        End With
    Loop
    Set rng = ActiveDocument.range
    With rng.Find
        .ClearFormatting
        .Replacement.ClearFormatting
        .Forward = True
        .Wrap = wdFindStop
        .Format = True
        .MatchWildcards = True
        .text = "(^13[0-9]{1;})^t"
        .Replacement.text = "\1.^t"
        .Execute Replace:=wdReplaceAll
    End With
ActiveDocument.range.Characters.First.Delete
Application.ScreenUpdating = True
Set rng = Nothing
End Sub
Attached Files
File Type: docx Test_Shelley.docx (26.3 KB, 3 views)
Reply With Quote
  #4  
Old 08-08-2024, 08:21 AM
Shelley Lou Shelley Lou is offline VBA Format manual numbering so auto numbering code can run Windows 10 VBA Format manual numbering so auto numbering code can run Office 2016
Expert
VBA Format manual numbering so auto numbering code can run
 
Join Date: Dec 2020
Posts: 259
Shelley Lou is on a distinguished road
Default VBA Format manual numbering so auto numbering code can run

Hi Vivka, thanks for taking the time to update the code - unfortunately your code did not work for me, it threw up a few issues. I've posted a couple of images below.

Code not removing the very last at the end of levels 2-4 consistently
Capture1.JPG

Code separating text with a tab
Capture2JPG.JPG

I've added this to the beginning of the code which isn't ideal as it can't capture any other rogue punctuation without it affecting the rest of the document text e.g. instances at the end of paragraphs containing a semi colon (; and). Not as easy as I thought!!

Code:
Set rng = ActiveDocument.Range
    With rng.Find
        .ClearFormatting
        .Replacement.ClearFormatting
        .Forward = True
        .Wrap = wdFindStop
        .Format = True
        .MatchWildcards = True
        .text = "([.])([ ])([A-Za-z])"
        .Replacement.text = "^t\3"
        .Execute Replace:=wdReplaceAll
    End With
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA Format manual numbering so auto numbering code can run VBA insert period after manual numbering Shelley Lou Word VBA 1 03-05-2023 03:45 AM
VBA Format manual numbering so auto numbering code can run VBA Remove manual numbering after Outline numbering Shelley Lou Word VBA 2 08-04-2021 12:24 AM
VBA Format manual numbering so auto numbering code can run VBA converting manual numbering to auto numbering Shelley Lou Word VBA 8 05-28-2021 01:08 AM
VBA Format manual numbering so auto numbering code can run Applying New Multi-Level List to Existing Document with Manual Numbering and Existing Styles stanley Word 4 12-15-2020 10:59 AM
page numbering for manual Bursal Word 1 07-29-2018 02:08 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:27 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