Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #10  
Old 10-21-2021, 08:53 PM
gmayor's Avatar
gmayor gmayor is offline Putting parentheses around sequence number of caption label Windows 10 Putting parentheses around sequence number of caption label Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,142
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

Documents comprise several separate story ranges which make up the whole - much like a stack of transparencies.

The code I posted earlier acts only on the main story range i.e. the body of the document. Where other ranges need to be processed you meed to address those ranges separately.
Code:
Sub Macro1()
Dim oFld As Field
Dim oStory As Range
    For Each oStory In ActiveDocument.StoryRanges
        For Each oFld In oStory.Fields
            If oFld.Type = wdFieldSequence Then
                If InStr(1, oFld.Code, "Appendix") > 0 Then
                    oFld.Result.InsertAfter ")"
                    oFld.Result.InsertBefore "("
                End If
            End If
        Next oFld
        oStory.Fields.Update
        If oStory.StoryType <> wdMainTextStory Then
            While Not (oStory.NextStoryRange Is Nothing)
                Set oStory = oStory.NextStoryRange
                For Each oFld In oStory.Fields
                    If oFld.Type = wdFieldSequence Then
                        If InStr(1, oFld.Code, "Appendix") > 0 Then
                            oFld.Result.InsertAfter ")"
                            oFld.Result.InsertBefore "("
                        End If
                    End If
                Next oFldoStory.Fields.Update
            Wend
        End If
        DoEvents
    Next oStory
lbl_Exit:
    Set oStory = Nothing
    Set oFld = Nothing
    Exit Sub
End Sub
As your Word crashed - reboot the laptop and see https://www.gmayor.com/what_to_do_when_word_crashes.htm regarding orphaned files.
__________________
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
 

Tags
find & replace, find replace;wildcards, word 19



Similar Threads
Thread Thread Starter Forum Replies Last Post
Formula for number sequence 14spar15 Excel Programming 4 03-18-2018 07:00 PM
Putting parentheses around sequence number of caption label Assigning a string variable to a userform label caption Larry_1 Excel Programming 3 12-18-2017 06:59 AM
Putting parentheses around sequence number of caption label how to have two formats in the Caption style: Label – number - text? Jamal NUMAN Word 39 03-14-2017 06:32 PM
Putting parentheses around sequence number of caption label Custom caption list label lost in a new Word session New Daddy Word 1 09-22-2013 09:21 AM
Custom caption label annoyance zac Word 1 08-29-2010 09:56 AM

Other Forums: Access Forums

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