Advanced Find and Replace in Microsoft Word.docx
《Advanced Find and Replace in Microsoft Word.docx》由会员分享,可在线阅读,更多相关《Advanced Find and Replace in Microsoft Word.docx(35页珍藏版)》请在冰豆网上搜索。
AdvancedFindandReplaceinMicrosoftWord
AdvancedFindandReplaceinMicrosoftWord
JackM.Lyon
©2002bytheEditorium.Allrightsreserved.
Contents
Preface3
SearchingwithCodes4
MicrosoftWord’sBuilt-inCodes4
SearchingforSpecialCharacters5
ANSICharacterCodes6
What’sThatCharacter?
7
Replacingwith“FindWhatText”8
Example:
FormattingNoteNumbers8
UsingWildcards10
TheBasics10
WildcardCombinations11
WildcardRanges13
WildcardGrouping14
Usingthe“FindWhatExpression”Wildcard16
WildcardsintheRealWorld18
Example118
Example219
Example319
Two-StepSearching20
Step120
Step221
Reference22
Preface
Thisdocumentisacompilationofarticlesthatoriginallyappearedinmyemailnewsletter,EditoriumUpdate.MicrosoftWord’sadvancedsearchfeaturesareextremelypowerful,butthey’realsovirtuallyundocumented.Mostexplanationsoftheirusehavebeenlimitedtoasimpletableofvariouswildcards.Iwrotethesearticlestoremedythatsituation.
Asyoureadthesearticles,youmaywanttoactuallytrythetechniquesinMicrosoftWord,usingsomejunkdocumentsthatyounolongerneed.Doingsowillhelpyoulearnmorethanjustreadingtheinstructions.
IhopethesearticleswillhelpyouunderstandhowusefulWord’sadvancedsearchfeaturescanbeandhowmuchtimetheycansaveyou.Usingthesefeatures,youcanquicklyfixrepetitiveproblemsthatwouldtakehourstocorrectbyhand.
Enjoy!
SearchingwithCodes
Whyshouldyou,asaneditor,writer,orpublisher,careaboutsomethingas“technical”assearchingwithcodes?
Becausetheymakeitpossibletofindandreplacethingsyouordinarilycouldn’t,suchasparagraphbreaks,dashes,andsymbols.Thiscanbeabighelpincleaningupallkindsofeditorialandtypographicalproblemsthatyou’dotherwisehavetofixbyhand.
Thereareactuallytwodifferentkindsofcodes:
1.MicrosoftWord’sbuilt-incodes(suchas^pforparagraphbreaksand^tfortabs).
2.ANSIcharactercodes(suchas^013forparagraphbreaksand^009fortabs).
Bothkindsofcodesareuseful,butthelistofANSIcodesincludeseverycharacter(notincludingUnicodecharacters)youcanuseinMicrosoftWord.LaterI’llprovidealistofthesecodesandexplainhowtousethem.
MicrosoftWord’sBuilt-inCodes
First,I’llgiveyoualistofWord’sbuilt-incodes,whichyoucanuseinMicrosoftWord’sFindandReplacedialog(Edit/Replace).Forexample,ifyouwantedtofindanem dash,you’denterthefollowingcodeinthe“Findwhat”box:
^+
Toreplaceitwithanen dash,you’denterthisinthe“Replacewith”box:
^=
YoucanalsoinsertWord’sbuilt-incodesbyclickingtheSpecialbuttonintheFindandReplacedialogandthenselectingtheitemyouneed.Pleasenotethatyoucanusesomeofthecodesonlyinfindingtext,othersonlyinreplacing,andothersineitherone.
Youcanalsousecombinationsofcodes.Forexample,youcouldsearchfortabsfollowedbyparagraphbreaks(^t^p)andreplacethemwithparagraphbreaksalone(^p).
Andnow,here’sthelist.
Note
Foreasyreference,allthecodelistsarealsoincludedattheendofthisdocument.
CodesYouCanUseinthe
“FindWhat”and“ReplaceWith”Boxes
Character
Find
What
ReplaceWith
AnnotationMark(comment)
^a
Anycharacter
^?
Anydigit
^#
Anyletter
^$
Caretcharacter
^^
^^
Clipboardcontents
^c
Columnbreak
^n
^n
ContentsoftheFindWhatbox
^&
Emdash
^+
^+
Endash
^=
^=
Endnotemark
^e
Field
^d
Footnotemark
^f
Graphic
^g
Linebreak
^l
^l
Manualpagebreak
^m
^m
Nonbreakinghyphen
^~
^~
Nonbreakingspace
^s
^s
Optionalhyphen
^-
^-
Paragraphmark
^p
^p
Sectionbreak
^b
Tabcharacter
^t
^t
Whitespace
^w
SearchingforSpecialCharacters
AsIsaidabove,MicrosoftWordhasANSIcharactercodesyoucanusetofindcertainitemsthatarenotusuallyvisibleinthetext:
•Foracarriagereturn,youcanuse^013.
•Forasectionbreak,youcanuse^012.
•Forawordspace,youcanuse^032.
Ofcourse,youcanalsouseWord’sbuilt-incodesfromthetableabove,whichyoucaninsertintotheFinddialog’s“Findwhat”boxbyclickingthe“Special”button:
•Foracarriagereturn,youcanuse^p.
•Forasectionbreak,youcanuse^b.
•Forawordspace,youcanuse^w
(actually,anywhitespace).
Sowhywouldyouwanttousethefirstcodes?
Becauseifyou’refindingsomethingbyusingwildcards,thesecondoneswon’twork.Forexample,let’ssaythat(forsomereason)you’researchingfor“wh”followedbyanyothercharacter(thewildcardforwhichis“?
”),followedbyacarriagereturn.IntheFinddialog’s“Findwhat”box,youenterthis:
wh?
^p
AndtomakeWordsearchforthewildcardratherthananactualquestionmark,youputacheckintheboxlabeled“Usewildcards.”
Finally,youclicktheFindbutton.Whathappens?
Yougetanerrormessage:
^pisnotavalidspecialcharacterfortheFindWhatboxorisnotsupportedwhentheUseWildcardscheckboxisselected.
“Wellthen,how,”youpolitelyaskyourcomputer,“amIsupposedtofindwhatI’mlookingfor?
”Asusual,itdoesn’treply,buthere’stheansweranyway.Inthe“Findwhat”box,youenterthis:
wh?
^013
Andthatwilldothejob.(OnaPC.OnaMacintosh,usingnumericcodesmaynotworkwhenusingwildcards.Here’salittletrick,however.Tryenclosingthecodeinsquarebrackets,andprecedethecodewithabackslash.Forexample,tofindacarriagereturnonaMac,tryusing[\^013].)
Ordinarily,youshouldprobablyuseWord’sbuilt-incodes,suchas^pand^b.Butwhenthosedon’twork,nowyou’vegotanalternative.
ANSICharacterCodes
Youcanalsosearchforanycharactersusingnumericcharactercodes(technicallyANSInumbers).I’mincludingthelistattheendofthisdocument,withcodesforbothPCandMacintosh,althoughImakenoguaranteesabouthowthecharactersthemselveswillshowup.
Also,you’llnoticethatIhaven’tincludedthecodesforsuchordinarycharactersaslettersofthealphabet,sinceyoucansearchforthesebyusingthecharactersthemselves.Nocodeisneeded.
Tousethecodesforfindingorreplacingspecialcharacters,simplyinsertthem,precededbyacaretandazero,inthe“Findwhat”or“Replacewith”boxesinMicrosoftWord’sFindandReplacedialogbox.
Forexample,ifyouwantedtofindauwithanumlaut,you’denterthefollowingcodeinthe“Findwhat”boxonaPC:
^0252OnaMacintosh,you’denterthis:
^0159
Youcanalsousemanyofthecodestoinsertspecialcharactersintoyourdocuments.Todoso:
1.TurnonNumLockforthenumerickeypad.
2.HolddowntheALTkey.
3.Onthenumerickeypad,typeazerofollowedbythecode.
4.ReleasetheALTkey.
Thecharacterwillbeinsertedintoyourdocument.
WARNING:
Usenumericcodestoreplaceparagraphreturnsandsectionbreaksonlywhenabsolutelynecessary,becauseWordstoresformattinginformationinthesecharacters.TrytosticktoWord’sbuilt-incodeswhenyoucan.Also,beawarethatsomefontsassigndifferentcharacterstothenumericcodes.ThelistbelowshouldbeaccurateforTimesNewRomanonaPCandTimesonaMacintosh.
What’sThatCharacter?
Butwhatifyou’retryingtofindandreplacesomeobscurecharacterinanunusualfont?
Here'sthescenario:
Youopenagiantdocumentfromaclientandstartlookingthroughit.Butwhat'sthis?
Thesameoddcharacteratthebeginningofeveryparagraph.Mustbesomekindoffiletranslationerror.Odderstill,MicrosoftWordwon'tletyoupastethecharacterintoitsFindandReplacedialog,sohowareyougoingtogetridofthemall?
Byhand?
Horrors!
Ifyouknewthecharacter'snumericcode,youcouldsearchforit.Butthischaracterisn'tontheusuallist.Howcanyoufindoutitsnumericcode?
ByusingourtrustyNextCharactermacro:
ForMicrosoftWord6or7(95):
'Macrostartshere
NextChar$=Str$(Asc(Selection$()))
MsgBox"Thecodeforthenextcharacteris"\+NextChar$+".","NextCharacter"
'Macroendshere
ForMicrosoftWord8(97or98)
or9(2000or2001)
'Macrostartshere
DimNextChar$
NextChar$=Str(Asc(WordBasic.[Selection$]()))
WordBasic.MsgBox_"Thecodeforthenextcharacteris"+NextChar$+".",_"NextCharacter"
'Macroendshere
ToCreatetheMacro
1.Copytheappropriatemacrofromthisnewsletter.
2.Clickthe"Tools"menuatthetopofyourWordwindow.
3.Click"Macro."
4.InWord97,98,2000,or2001,click"Macros."
5.Makesure"MacrosAvailableIn"shows"Normal.dot."
6.Typeanameforthemacrointhe"MacroName"box--"NextCharacter"shoulddonicely.
7.Click"Create."
8.Pastethemacroatthecurrentinsertionpoint.
9.InWord6or7,click"File,"then"Close,"then"Yes."InWord97,98,2000,or2001,click"File,"then"CloseandReturntoMicrosoftWord."
ToRuntheMacro:
1.Putyourcursorinfrontofthecharacterwhosenumericcodeyouwanttoknow.
2.Clickthe"Tools"menuatthetopofyourWordwindow.
3.Click"Macro."
4.InWord97,98,2000,or2001,click"Macros."
5.Makesure"MacrosAvailableIn"shows"Normal.dot."
6.Selectthemacro(probably"NextCharacter")inthe"MacroName"box.
7.Click"Run."
Afteryourunthemacro,amessageboxwillappearonyourscreenwiththenumericcodeyouneed.
Replacingwith“FindWhatText”
Ifyou’refacedwithacomplextaskusingMicrosoftWord’sFindandReplacefeature,the“FindWhatText”replacementcodemaycomeinhandy.Forexample,let’ssayyouneedtoaddtheHTMLitalictagsandaroundanythingformattedwithitalic.(Ifyoudon’tunderstandHTML,don’tworry.You’llsoonseethepointofthisexample.)Youmightthinkyou’dneedamacrotoaddthetags,butyoudon’t.Youcaneasilyd