Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #4  
Old 02-18-2023, 10:33 PM
gmayor's Avatar
gmayor gmayor is offline Output at the end of the text of all links using VBA Windows 10 Output at the end of the text of all links using VBA Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,144
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Given that you are attracted to autonumbering as suggested, the following macros will address that. The first replaces your numbered items with Sequence fields. The second will add a number using the same sequence and update the sequence to reflect the addition.
Code:
Sub ReplaceNumbers()
Dim oRng As Range
    ActiveWindow.ActivePane.View.ShowFieldCodes = True
    Set oRng = ActiveDocument.Range
    With oRng.Find
        Do While .Execute(findText:="\[[0-9]{1,}\]", _
                          MatchWildcards:=True, _
                          Wrap:=wdFindStop, _
                          Forward:=True) = True
            oRng.Fields.Add oRng, wdFieldSequence, "List\# ""'['0']'""", False
            oRng.Collapse 0
        Loop
    End With
    ActiveWindow.ActivePane.View.ShowFieldCodes = False
lbl_Exit:
Set oRng = Nothing
    Exit Sub
End Sub

Sub AddNumber()
Dim oRng As Range
Dim oField As Field
    ActiveWindow.ActivePane.View.ShowFieldCodes = True
    Set oRng = Selection.Range
    oRng.Fields.Add oRng, wdFieldSequence, "List\# ""'['0']'""", False
    oRng.Collapse 0
    ActiveWindow.ActivePane.View.ShowFieldCodes = False
    For Each oRng In ActiveDocument.StoryRanges
        For Each oField In oRng.Fields
            oField.Update
        Next oField
    Next oRng
lbl_Exit:
    Set oRng = Nothing
    Set oField = Nothing
    Exit Sub
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Userform to output specific text ~clover Word VBA 2 06-01-2019 07:04 AM
Output at the end of the text of all links using VBA Content Control Listbox output to text box possible? VGW Word VBA 2 07-05-2018 04:18 PM
Outlook Template: Trying to Output text and fields back2ict Outlook 0 07-03-2018 08:57 AM
How do I output text to a specific cell (x,y)? norwood Word VBA 2 01-31-2014 08:43 AM
Generating text output from PowerPoint picture/name slides bornslippy PowerPoint 2 12-05-2013 11:04 AM

Other Forums: Access Forums

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