![]() |
#10
|
||||
|
||||
![]()
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
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
Tags |
find & replace, find replace;wildcards, word 19 |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Formula for number sequence | 14spar15 | Excel Programming | 4 | 03-18-2018 07:00 PM |
![]() |
Larry_1 | Excel Programming | 3 | 12-18-2017 06:59 AM |
![]() |
Jamal NUMAN | Word | 39 | 03-14-2017 06:32 PM |
![]() |
New Daddy | Word | 1 | 09-22-2013 09:21 AM |
Custom caption label annoyance | zac | Word | 1 | 08-29-2010 09:56 AM |