Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Find and replace text within index codes
Hi, I have a huge document with index codes. I want to do some global find
and replaces on the text in some of the index codes. The problem is that some of this same text occurs outside the index codes in the body of the document and I dont want to change that. Is there a way to do a find and replace and specify that only text within the index codes gets replaced? Ive experimented with some things on my own using ^d and ^19, as well as specifying a search for hidden text, but so far nothing has worked. Is there a way to do this, if not using a regular built in Word feature then maybe with a macro? Thanks in advance for any help. |
#2
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Find and replace text within index codes
Unless the text appears as Hidden outside the XE field codes, you should be
able to search for the text in question, formatted as Hidden. You'll have to display Hidden text for Find to find it, though. -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA "Dale" wrote in message ... Hi, I have a huge document with index codes. I want to do some global find and replaces on the text in some of the index codes. The problem is that some of this same text occurs outside the index codes in the body of the document and I don't want to change that. Is there a way to do a find and replace and specify that only text within the index codes gets replaced? I've experimented with some things on my own using ^d and ^19, as well as specifying a search for hidden text, but so far nothing has worked. Is there a way to do this, if not using a regular built in Word feature then maybe with a macro? Thanks in advance for any help. |
#3
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Find and replace text within index codes
The following macro will do that: http://www.gmayor.com/installing_macro.htm
Note the search and replacement are case sensitive. Sub ReplaceIndex() Dim iFld As Long Dim fText, rText As String fText = InputBox("Enter text to be found", "Find Text") rText = InputBox("Enter text to replace found text", "Replace Text") Selection.HomeKey ActiveDocument.ActiveWindow.View.ShowFieldCodes = True For iFld = 1 To ActiveDocument.Fields.Count With ActiveDocument.Fields(iFld) If .Type = wdFieldIndexEntry Then If InStr(1, .Code, fText) 0 Then .Code.Text = Replace(.Code.Text, fText, rText) End If .Update End If End With Next iFld ActiveDocument.ActiveWindow.View.ShowFieldCodes = False End Sub -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Dale wrote: Hi, I have a huge document with index codes. I want to do some global find and replaces on the text in some of the index codes. The problem is that some of this same text occurs outside the index codes in the body of the document and I don't want to change that. Is there a way to do a find and replace and specify that only text within the index codes gets replaced? I've experimented with some things on my own using ^d and ^19, as well as specifying a search for hidden text, but so far nothing has worked. Is there a way to do this, if not using a regular built in Word feature then maybe with a macro? Thanks in advance for any help. |
#4
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Find and replace text within index codes
Hi, Suzanne, thanks for your reply. As it turns out, I had my show/hide on
but I didn't specifically have "hidden text" checked in Word Options, Display. I checked the box and it now works. Thank you so much! "Suzanne S. Barnhill" wrote: Unless the text appears as Hidden outside the XE field codes, you should be able to search for the text in question, formatted as Hidden. You'll have to display Hidden text for Find to find it, though. -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA "Dale" wrote in message ... Hi, I have a huge document with index codes. I want to do some global find and replaces on the text in some of the index codes. The problem is that some of this same text occurs outside the index codes in the body of the document and I don't want to change that. Is there a way to do a find and replace and specify that only text within the index codes gets replaced? I've experimented with some things on my own using ^d and ^19, as well as specifying a search for hidden text, but so far nothing has worked. Is there a way to do this, if not using a regular built in Word feature then maybe with a macro? Thanks in advance for any help. |
#5
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Find and replace text within index codes
Hi, Graham, thank you so much. Your macro worked great! Thanks again!
"Graham Mayor" wrote: The following macro will do that: http://www.gmayor.com/installing_macro.htm Note the search and replacement are case sensitive. Sub ReplaceIndex() Dim iFld As Long Dim fText, rText As String fText = InputBox("Enter text to be found", "Find Text") rText = InputBox("Enter text to replace found text", "Replace Text") Selection.HomeKey ActiveDocument.ActiveWindow.View.ShowFieldCodes = True For iFld = 1 To ActiveDocument.Fields.Count With ActiveDocument.Fields(iFld) If .Type = wdFieldIndexEntry Then If InStr(1, .Code, fText) 0 Then .Code.Text = Replace(.Code.Text, fText, rText) End If .Update End If End With Next iFld ActiveDocument.ActiveWindow.View.ShowFieldCodes = False End Sub -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Dale wrote: Hi, I have a huge document with index codes. I want to do some global find and replaces on the text in some of the index codes. The problem is that some of this same text occurs outside the index codes in the body of the document and I don't want to change that. Is there a way to do a find and replace and specify that only text within the index codes gets replaced? I've experimented with some things on my own using ^d and ^19, as well as specifying a search for hidden text, but so far nothing has worked. Is there a way to do this, if not using a regular built in Word feature then maybe with a macro? Thanks in advance for any help. |
#6
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Find and replace text within index codes
Hi, Suzanne, I just tried the find and replace again and either I had some
other option checked when I first did it or else maybe it didn't work as I thought it did at first because now I can't get it to work again, even with the hidden text displayed. I can use Graham's macro to do the find and replace, but I'm just wondering what other option I might have had checked or unchecked that seemed to allow it to work the first time but not again. Or maybe I was mistaken and it just replaced the visible matches and I thought it worked on the hidden text. I guess I'm trying to do too many things at once. :} Sorry for the confusion, but thanks in advance for any information. "Suzanne S. Barnhill" wrote: Unless the text appears as Hidden outside the XE field codes, you should be able to search for the text in question, formatted as Hidden. You'll have to display Hidden text for Find to find it, though. -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA "Dale" wrote in message ... Hi, I have a huge document with index codes. I want to do some global find and replaces on the text in some of the index codes. The problem is that some of this same text occurs outside the index codes in the body of the document and I don't want to change that. Is there a way to do a find and replace and specify that only text within the index codes gets replaced? I've experimented with some things on my own using ^d and ^19, as well as specifying a search for hidden text, but so far nothing has worked. Is there a way to do this, if not using a regular built in Word feature then maybe with a macro? Thanks in advance for any help. |
#7
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Find and replace text within index codes
You are welcome
-- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Dale wrote: Hi, Graham, thank you so much. Your macro worked great! Thanks again! "Graham Mayor" wrote: The following macro will do that: http://www.gmayor.com/installing_macro.htm Note the search and replacement are case sensitive. Sub ReplaceIndex() Dim iFld As Long Dim fText, rText As String fText = InputBox("Enter text to be found", "Find Text") rText = InputBox("Enter text to replace found text", "Replace Text") Selection.HomeKey ActiveDocument.ActiveWindow.View.ShowFieldCodes = True For iFld = 1 To ActiveDocument.Fields.Count With ActiveDocument.Fields(iFld) If .Type = wdFieldIndexEntry Then If InStr(1, .Code, fText) 0 Then .Code.Text = Replace(.Code.Text, fText, rText) End If .Update End If End With Next iFld ActiveDocument.ActiveWindow.View.ShowFieldCodes = False End Sub -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Dale wrote: Hi, I have a huge document with index codes. I want to do some global find and replaces on the text in some of the index codes. The problem is that some of this same text occurs outside the index codes in the body of the document and I don't want to change that. Is there a way to do a find and replace and specify that only text within the index codes gets replaced? I've experimented with some things on my own using ^d and ^19, as well as specifying a search for hidden text, but so far nothing has worked. Is there a way to do this, if not using a regular built in Word feature then maybe with a macro? Thanks in advance for any help. |
#8
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Find and replace text within index codes
If you have Hidden text displayed (which you would have to have to see the
XE field codes) and have specified Hidden formatting for the search, then it should work. -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA "Dale" wrote in message ... Hi, Suzanne, I just tried the find and replace again and either I had some other option checked when I first did it or else maybe it didn't work as I thought it did at first because now I can't get it to work again, even with the hidden text displayed. I can use Graham's macro to do the find and replace, but I'm just wondering what other option I might have had checked or unchecked that seemed to allow it to work the first time but not again. Or maybe I was mistaken and it just replaced the visible matches and I thought it worked on the hidden text. I guess I'm trying to do too many things at once. :} Sorry for the confusion, but thanks in advance for any information. "Suzanne S. Barnhill" wrote: Unless the text appears as Hidden outside the XE field codes, you should be able to search for the text in question, formatted as Hidden. You'll have to display Hidden text for Find to find it, though. -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA "Dale" wrote in message ... Hi, I have a huge document with index codes. I want to do some global find and replaces on the text in some of the index codes. The problem is that some of this same text occurs outside the index codes in the body of the document and I don't want to change that. Is there a way to do a find and replace and specify that only text within the index codes gets replaced? I've experimented with some things on my own using ^d and ^19, as well as specifying a search for hidden text, but so far nothing has worked. Is there a way to do this, if not using a regular built in Word feature then maybe with a macro? Thanks in advance for any help. |
#9
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Find and replace text within index codes
Hi, Suzanne, thanks for your response. I've been experimenting and I can't
get it to work on the text in the index codes. I tried formatting some text outside the index codes as hidden text and it works on that. It just doesn't seem to recognize the hidden text within the index codes. Right now I have the following options checked in Word Options, Display: Hidden text, Show all formatting marks. Is there another option I have to have checked somewhere? I'm using Word 2007. I'm not sure if that would make a difference. I'm still not used to 2007. I feel like I'm probably missing something really obvious. Thanks for your help! "Suzanne S. Barnhill" wrote: If you have Hidden text displayed (which you would have to have to see the XE field codes) and have specified Hidden formatting for the search, then it should work. -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA "Dale" wrote in message ... Hi, Suzanne, I just tried the find and replace again and either I had some other option checked when I first did it or else maybe it didn't work as I thought it did at first because now I can't get it to work again, even with the hidden text displayed. I can use Graham's macro to do the find and replace, but I'm just wondering what other option I might have had checked or unchecked that seemed to allow it to work the first time but not again. Or maybe I was mistaken and it just replaced the visible matches and I thought it worked on the hidden text. I guess I'm trying to do too many things at once. :} Sorry for the confusion, but thanks in advance for any information. "Suzanne S. Barnhill" wrote: Unless the text appears as Hidden outside the XE field codes, you should be able to search for the text in question, formatted as Hidden. You'll have to display Hidden text for Find to find it, though. -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA "Dale" wrote in message ... Hi, I have a huge document with index codes. I want to do some global find and replaces on the text in some of the index codes. The problem is that some of this same text occurs outside the index codes in the body of the document and I don't want to change that. Is there a way to do a find and replace and specify that only text within the index codes gets replaced? I've experimented with some things on my own using ^d and ^19, as well as specifying a search for hidden text, but so far nothing has worked. Is there a way to do this, if not using a regular built in Word feature then maybe with a macro? Thanks in advance for any help. |
#10
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Find and replace text within index codes
I suspect that Word is just not treating XE fields as "simple" Hidden text.
You can search for fields, as you know, with ^d or ^19, but that type of search requires that you be performing some action on the entire field. And you can search for the text within fields by typing the field code (in this case XE) along with the text to be replaced, which doesn't require that you specify Hidden text. This does demonstrably work (I just tried it). You do have to have Hidden text displayed so Word can find the XE fields, of course. My replace operation was as follows: Find what: XE "an index entry" Replace with : XE "another index entry" Obviously, this isn't much help if you're trying to replace just one part of many field, replacing "Smith" with "Jones," for example, in fields such as { XE "Mary Smith" }, { XE "John Smith" }, and so on (though you might be able to accomplish this with wildcards). OTOH, if if you have { XE "Smith:Mary" } and { XE "Smith:John"), you could search for just XE "Smith and replace with XE "Jones. -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA "Dale" wrote in message ... Hi, Suzanne, thanks for your response. I've been experimenting and I can't get it to work on the text in the index codes. I tried formatting some text outside the index codes as hidden text and it works on that. It just doesn't seem to recognize the hidden text within the index codes. Right now I have the following options checked in Word Options, Display: Hidden text, Show all formatting marks. Is there another option I have to have checked somewhere? I'm using Word 2007. I'm not sure if that would make a difference. I'm still not used to 2007. I feel like I'm probably missing something really obvious. Thanks for your help! "Suzanne S. Barnhill" wrote: If you have Hidden text displayed (which you would have to have to see the XE field codes) and have specified Hidden formatting for the search, then it should work. -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA "Dale" wrote in message ... Hi, Suzanne, I just tried the find and replace again and either I had some other option checked when I first did it or else maybe it didn't work as I thought it did at first because now I can't get it to work again, even with the hidden text displayed. I can use Graham's macro to do the find and replace, but I'm just wondering what other option I might have had checked or unchecked that seemed to allow it to work the first time but not again. Or maybe I was mistaken and it just replaced the visible matches and I thought it worked on the hidden text. I guess I'm trying to do too many things at once. :} Sorry for the confusion, but thanks in advance for any information. "Suzanne S. Barnhill" wrote: Unless the text appears as Hidden outside the XE field codes, you should be able to search for the text in question, formatted as Hidden. You'll have to display Hidden text for Find to find it, though. -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA "Dale" wrote in message ... Hi, I have a huge document with index codes. I want to do some global find and replaces on the text in some of the index codes. The problem is that some of this same text occurs outside the index codes in the body of the document and I don't want to change that. Is there a way to do a find and replace and specify that only text within the index codes gets replaced? I've experimented with some things on my own using ^d and ^19, as well as specifying a search for hidden text, but so far nothing has worked. Is there a way to do this, if not using a regular built in Word feature then maybe with a macro? Thanks in advance for any help. |
#11
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Find and replace text within index codes
Hi, Suzanne, thanks for the information. I tried your suggestion using XE
and a word I was searching for and that did work. This is the first time I've used index codes extensively so I'm learning a lot. Thank you very much for all your help. "Suzanne S. Barnhill" wrote: I suspect that Word is just not treating XE fields as "simple" Hidden text. You can search for fields, as you know, with ^d or ^19, but that type of search requires that you be performing some action on the entire field. And you can search for the text within fields by typing the field code (in this case XE) along with the text to be replaced, which doesn't require that you specify Hidden text. This does demonstrably work (I just tried it). You do have to have Hidden text displayed so Word can find the XE fields, of course. My replace operation was as follows: Find what: XE "an index entry" Replace with : XE "another index entry" Obviously, this isn't much help if you're trying to replace just one part of many field, replacing "Smith" with "Jones," for example, in fields such as { XE "Mary Smith" }, { XE "John Smith" }, and so on (though you might be able to accomplish this with wildcards). OTOH, if if you have { XE "Smith:Mary" } and { XE "Smith:John"), you could search for just XE "Smith and replace with XE "Jones. -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA "Dale" wrote in message ... Hi, Suzanne, thanks for your response. I've been experimenting and I can't get it to work on the text in the index codes. I tried formatting some text outside the index codes as hidden text and it works on that. It just doesn't seem to recognize the hidden text within the index codes. Right now I have the following options checked in Word Options, Display: Hidden text, Show all formatting marks. Is there another option I have to have checked somewhere? I'm using Word 2007. I'm not sure if that would make a difference. I'm still not used to 2007. I feel like I'm probably missing something really obvious. Thanks for your help! "Suzanne S. Barnhill" wrote: If you have Hidden text displayed (which you would have to have to see the XE field codes) and have specified Hidden formatting for the search, then it should work. -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA "Dale" wrote in message ... Hi, Suzanne, I just tried the find and replace again and either I had some other option checked when I first did it or else maybe it didn't work as I thought it did at first because now I can't get it to work again, even with the hidden text displayed. I can use Graham's macro to do the find and replace, but I'm just wondering what other option I might have had checked or unchecked that seemed to allow it to work the first time but not again. Or maybe I was mistaken and it just replaced the visible matches and I thought it worked on the hidden text. I guess I'm trying to do too many things at once. :} Sorry for the confusion, but thanks in advance for any information. "Suzanne S. Barnhill" wrote: Unless the text appears as Hidden outside the XE field codes, you should be able to search for the text in question, formatted as Hidden. You'll have to display Hidden text for Find to find it, though. -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA "Dale" wrote in message ... Hi, I have a huge document with index codes. I want to do some global find and replaces on the text in some of the index codes. The problem is that some of this same text occurs outside the index codes in the body of the document and I don't want to change that. Is there a way to do a find and replace and specify that only text within the index codes gets replaced? I've experimented with some things on my own using ^d and ^19, as well as specifying a search for hidden text, but so far nothing has worked. Is there a way to do this, if not using a regular built in Word feature then maybe with a macro? Thanks in advance for any help. |
Reply |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Find Replace Figure SEQ Field codes | Microsoft Word Help | |||
Find duplicate text using copy and paste, not Find and Replace | Microsoft Word Help | |||
Index: find/replace and delinking | Microsoft Word Help | |||
find/replace in between text | Microsoft Word Help | |||
Index field codes appear even when Hidden Text is turned off | Microsoft Word Help |