Page 1 of 3 123 LastLast
Results 1 to 15 of 31
  1. #1
    Star Lounger
    Join Date
    Apr 2003
    Location
    Morgantown, Pennsylvania, USA
    Posts
    94
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Replacing with Special Characters (2003)

    Hello,

    Rand into something the other day. I was creating some documentation, and using a keystroke font to show keys. You know, instead of writing CRTL + C I was putting characters that looked like keys. Well, the character for the F6 key in this particular font is the caret symbol (^). When I tried to do a replace, searching for F6 and replacing with ^, word informed me that I couldn't use the caret symbol in the replace line because "^ is not a valid special character for the Replace With box."

    I eventually did it manually, but is there a solution to this? And what other characters can't you use when doing global replaces?

    Thanks.

  2. #2
    Platinum Lounger
    Join Date
    Jan 2001
    Posts
    3,788
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Replacing with Special Characters (2003)

    Hi Bob

    The option to find/replace special characters is accessed by selecting the more button on the find/replace dialog. You can then click on the special button to list the special characters to find or replace including the caret character. The attachment show the options available for the "replace with" box.
    Attached Images Attached Images

  3. #3
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Replacing with Special Characters (2003)

    You didn't say, but the trick in this case is the use ^^ (two carets in a row) to replace something with a caret. If the Use wildcards checkbox is checked, some additional characters become illegal. It is best to use the help system to ferret those out. That and a lot of trial and error. <img src=/S/laugh.gif border=0 alt=laugh width=15 height=15>

  4. #4
    5 Star Lounger
    Join Date
    May 2001
    Location
    Stuttgart, Baden-W, Germany
    Posts
    931
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Replacing with Special Characters (2003)

    In old versions, the "Special" popup listed many of the shortcuts, so it was easy to learn them.

    I wrote to MSWish, asking them to display all the shortcuts (for normal and wildcard searches).
    They listened... and removed them all <img src=/S/beep.gif border=0 alt=beep width=15 height=15>

    <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16> Klaus

  5. #5
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Find/Replace Special Characters (Word)

    <P ID="edit" class=small>(Edited by Phil Rabichow on 17-Nov-04 14:42. to add information that was left out. A big thanks to Klaus Linke for these additions.)</P>
    Bob:
    Here is a list of special characters that you can use with Find/Replace, depending upon whether Use Wildcards is selected.

    <big>Special Characters You Can Find & Replace w/o Use Wildcards</big>
    You can search for and replace the following special characters by entering them in the Find What and Replace With boxes. You can also insert many of these characters by clicking the Special button, and then selecting the operator you want.

    To find or replace special characters using an EditFind or EditReplace instruction, specify the following codes for the .Find and .Replace arguments. Press SHIFT+6 for the ^ symbol and make sure to use lowercase letters.

    <table border=1><td align=center valign=top>characters</td><td align=center valign=top>string matches</td><td align=center valign=top>^1</td><td valign=top>Picture (Except pictures with Float Over Text property, Word 98 Macintosh Edition)</td><td align=center valign=top>^2</td><td valign=top>Auto-referenced footnotes</td><td align=center valign=top>^5</td><td valign=top>Comment mark</td><td align=center valign=top>^9</td><td valign=top>Tab</td><td align=center valign=top>^11</td><td valign=top>New line</td><td align=center valign=top>^12</td><td valign=top>Page OR section break</td><td align=center valign=top>^13</td><td valign=top>Carriage return</td><td align=center valign=top>^14</td><td valign=top>Column break</td><td align=center valign=top>^19</td><td valign=top>Opening field brace (when the field braces are visible)</td><td align=center valign=top>^21</td><td valign=top>Closing field brace (when the field braces are visible)</td><td align=center valign=top>^?</td><td valign=top>Word 6.x and later: Any single character (not valid in the Replace box)</td><td align=center valign=top>^-</td><td valign=top>Optional hyphen</td><td align=center valign=top>^~</td><td valign=top>Non-breaking hyphen</td><td align=center valign=top>^^</td><td valign=top>Caret character</td><td align=center valign=top>^#</td><td valign=top>Any digit (Word 6.x and later)</td><td align=center valign=top>^$</td><td valign=top>Any letter (Word 6.x and later)</td><td align=center valign=top>^&</td><td valign=top>Contents of Find What box (Replace box only) (Word 6.x and later)</td><td align=center valign=top>^+</td><td valign=top>Em Dash (not valid in the Replace box) (Word 6.x and later)</td><td align=center valign=top>^=</td><td valign=top>En Dash (not valid in the Replace box) (Word 6.x and later)</td><td valign=top>^u8195</td><td valign=top>Em Space Unicode character value search (not valid in the Replace box)</td><td valign=top>^u8194</td><td valign=top>En Space Unicode character value search (not valid in the Replace box)</td><td align=center valign=top>^a</td><td valign=top>Comment (not valid in the Replace box) (Word 6.x - Word 7.0)</td><td align=center valign=top>^b</td><td valign=top>Section Break (not valid in the Replace box) (Word 6.x and later)</td><td align=center valign=top>^c</td><td valign=top>Replace with Clipboard contents (Replace box only)</td><td align=center valign=top>^d</td><td valign=top>Field(Word 6.x and later)</td><td align=center valign=top>^e</td><td valign=top>Endnote Mark (not valid in the Replace box) (Word 6.x and later)</td><td align=center valign=top>^f</td><td valign=top>Footnote Mark (not valid in the Replace box) (Word 6.x and later)</td><td align=center valign=top>^g</td><td valign=top>Graphic(Word 6.x and later)</td><td align=center valign=top>^l</td><td valign=top>New line</td><td align=center valign=top>^m</td><td valign=top>Manual Page Break (Word 6.x and later)</td><td align=center valign=top>^n</td><td valign=top>Column break (Word 6.x and later)</td><td align=center valign=top>^t</td><td valign=top>Tab</td><td align=center valign=top>^p</td><td valign=top>Paragraph mark</td><td align=center valign=top>^s</td><td valign=top>Non-breaking space</td><td align=center valign=top>^w</td><td valign=top>White space (space, non-breaking space, tab; not valid in the Replace box)</td><td align=center valign=top>^nnn</td><td valign=top>Where "n" is an ASCII character number; you can use this (& the next one) to Find & delete square boxes like this </td><td align=center valign=top>^0nnn</td><td valign=top>Same as above, but uses ANSI characters (ALT+nnn PC only)</td><td valign=top>^unnnn</td><td valign=top>Word 97 Unicode character search where "n" is a decimal number corresponding to the Unicode character value.</td></table>
    NOTE: To search for a specific field, such as an XE (Index Entry) field, use the following
    syntax:

    ^19<field name>

    When you work with either the Search or Replace command, you can use the CTRL key to search or replace the following:

    Ctrl+C, Ctrl+V, Ctrl+X to copy/paste/cut, and Ctrl+Z to undo
    Ctrl+1 = line spacing: Single
    Ctrl+5 = line spacing: 1.5 lines
    Ctrl+2 = line spacing: Double
    Ctrl+Shift+W = Word underline
    Ctrl+Shift+D = Double underline
    Ctrl+Shift+A = All caps
    Ctrl+Shift+K = Small caps/Not small caps
    Ctrl+Shift+H = Hidden/Not Hidden
    Ctrl+Spacebar removes character formatting (just like outside the Find/Replace box). In other words, if you're searching for Body Text style Bold, you can remove all formatting by pressing Alt+t (since it's a hotkey). You can remove just the bold attribute by pressing Ctrl+Spacebar.
    Ctrl+Q removes paragraph-level formatting selectively.

    Ctrl+B = Bold/Not Bold
    Ctrl+U = Underline
    Ctrl+I = Italic
    Ctrl+Plus = Subscript
    Shift+Ctrl+Plus = Superscript
    Ctrl+L = Left-Aligned Text
    Ctrl+R = Right-Aligned Text
    Ctrl+E = Centered Text
    Ctrl+J = Justified (All Text)
    Ctrl+N = New (Finds text added with Tracked Changes On; stopped working in Word 2002/2003)

    Notes:
    If you omit the optional hyphen code, Word finds all matching text, including text with optional hyphens. If you include the optional hyphen code, Word finds only words with optional hyphens in the same position. For example, if you specify .Find = "type^-writer" Word finds "type-writer", but not "typewriter". You cannot search for hyphens that Word inserted automatically with the Hyphenation command (Tools menu).

    White space includes any number and combination of normal and nonbreaking spaces, tab characters, and paragraph marks.

    <big>Special Characters That Can't Be Used With Use Wildcards</big>
    If you select Use Wildcards in the Find or Replace dialog box, certain special characters cannot be used in the Find What text box:

    When Use Wildcards is selected, Word uses an entirely different search engine. This alternative search engine is not designed to search for the special characters listed below.

    To find the characters listed above when you have Use Wildcards selected, use the following substitutes in the Find What box:
    <table border=1><td align=center valign=top>char</td><td align=center valign=top>sub</td><td align=center valign=top>meaning</td><td valign=top>^p</td><td valign=top>^13</td><td valign=top>Paragraph mark</td><td valign=top>^e</td><td valign=top>^2</td><td valign=top>Auto-numbered endnote reference mark (see Note 1)</td><td valign=top>^d</td><td valign=top></td><td valign=top>Field (see Note 2)</td><td valign=top>^f</td><td valign=top>^2</td><td valign=top>Auto-numbered footnote reference mark</td><td valign=top>^b</td><td valign=top>^12</td><td valign=top>Section break or page break (see Note 3)</td><td valign=top>^w</td><td valign=top>sp{1,}</td><td valign=top>White space=any combination of spaces &/or tabs (see Note 4)</td></table>
    1. When using these substitutes, it is not possible to differentiate between endnote and footnote reference marks.
    2. There is no equivalent substitute for ^d (Field).
    3. When using ^12 to search for section breaks, page breaks will also be found by this pattern. Thus, ^12 is a limited substitute for ^b
    4. For the substitute of ^w (white space), "<space>" means that a space character should precede the "{1,}". Do not type out "<space>" in the Find What text box.
    5. The substitutes should be used in the find box only DO NOT use them in the replace box.

    Note that the workaround for endnotes and footnotes is the same (^e & ^f become ^2). This means that you cannot differentiate between these characters when wildcard searching (pattern matching). In addition, you cannot search for a field (^d) when using wildcard searching. Searching for white space (^w) is also a little different. You must type a space (press the space bar) and then enter the pattern {1,}. This causes Word to search for one or more spaces. This is not identical because white space includes tabs.

    Cheers,

  6. #6
    3 Star Lounger
    Join Date
    Jun 2001
    Location
    Los Angeles, California, USA
    Posts
    289
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Find/Replace Special Characters (Word)

    Fabulous, as always. An invaluable chart. Thanks Phil and Klaus.

    Van.

  7. #7
    3 Star Lounger rcbjr2's Avatar
    Join Date
    Jan 2001
    Location
    Matthews, NC
    Posts
    279
    Thanks
    6
    Thanked 1 Time in 1 Post

    Re: Find/Replace Special Characters (Word)

    I'm having trouble with a macro to search and replace hard returns. However, it works in just about all docs except for one of mine. The idea is to search for a space followed by a hard return and replace it with just the hard return. Here's the code I've been using.

    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
    .Text = " ^p"
    .Replacement.Text = "^p"
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchWholeWord = False
    .MatchWildcards = False
    End With
    Selection.Find.Execute
    While Selection.Find.Found
    Selection.HomeKey Unit:=wdStory
    Selection.Find.Execute Replace:=wdReplaceAll
    Selection.Find.Execute
    Wend

    I've attached a doc that makes the macro go into an endless loop. At the end of

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Find/Replace Special Characters (Word)

    I don't see an attachment <img src=/S/scratch.gif border=0 alt=scratch width=25 height=29>

  9. #9
    5 Star Lounger
    Join Date
    May 2001
    Location
    Stuttgart, Baden-W, Germany
    Posts
    931
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Find/Replace Special Characters (Word)

    You can replace ^w^p with ^p (^w being the placeholder for whitespace).
    Word will refuse to replace paragraph marks right before a table, which leads to your endless loop.
    If you need to fix that, you'd need to remove the space by some other means than a replacement, say find " ^p" and then delete the first character in the selection: Selection.Characters(1).Delete.<pre> With Selection.Find
    .Text = " ^p"
    .Forward = True
    .Wrap = wdFindContinue
    .MatchWildcards = False
    End With
    While Selection.Find.Execute
    Selection.Characters(1).Delete
    Wend
    </pre>

    <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16> Klaus

  10. #10
    3 Star Lounger rcbjr2's Avatar
    Join Date
    Jan 2001
    Location
    Matthews, NC
    Posts
    279
    Thanks
    6
    Thanked 1 Time in 1 Post

    Re: Find/Replace Special Characters (Word)

    Shoot, I did it again--I spelled checked after posting the attachment! <g> Anyway, here it is.

    Thx.

    -Rich Belthoff
    Attached Files Attached Files

  11. #11
    3 Star Lounger rcbjr2's Avatar
    Join Date
    Jan 2001
    Location
    Matthews, NC
    Posts
    279
    Thanks
    6
    Thanked 1 Time in 1 Post

    Re: Find/Replace Special Characters (Word)

    Klaus,

    Thanks for the suggestion. Your code works for almost all of the " ^p" pairings, especially the one before a table, but it usually leaves a few in the document, like those within the table itself. If I re-run the macro, it catches the rest of them. I'm trying to avoid re-running the macro. I used to do this by hand and search and replace, and I'd have to run the replace several times to get them all. In my original code, is there anyway to determine if the macro gets in an endless loop and break it? I don't think there's a way to search for a space followed by a hard return followed by a table, is there? BTW, are there other things in Word that could follow a ^p that Word won't replace, like line returns instead of hard returns followed by a table, or hard returns followed by something else, maybe a text box or something? My macro worked great on the first few files I tried it on, but then it hit this snage with the table in the file I uploaded (finally this morning).

    Thx.

    -Rich Belthoff

  12. #12
    5 Star Lounger
    Join Date
    May 2001
    Location
    Stuttgart, Baden-W, Germany
    Posts
    931
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Find/Replace Special Characters (Word)

    Hi Rich,

    Could you post a table sample where you have to run the code twice?

    Whitespace at the end of table cells would need to be handled separately: ^p won't find the end-of-cell-markers

  13. #13
    3 Star Lounger rcbjr2's Avatar
    Join Date
    Jan 2001
    Location
    Matthews, NC
    Posts
    279
    Thanks
    6
    Thanked 1 Time in 1 Post

    Re: Find/Replace Special Characters (Word)

    OK, let me try the file again. It went to 103k with all my messing, so I've edited it back down to 80k, so here it is.

    Thx.

    -Rich Belthoff
    Attached Files Attached Files

  14. #14
    5 Star Lounger
    Join Date
    May 2001
    Location
    Stuttgart, Baden-W, Germany
    Posts
    931
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Find/Replace Special Characters (Word)

    Don't have too much time right now to look at it... But my guess is that the problem is story ranges.

    You have some trailing whitespace in headers, footers, footnotes...
    VBA always only searches the story range it's currently in, and probably the macro gets hung in some footer or somewhere, and fails to remove the rest of the trailing spaces.

    This article should help get around that problem.

    So you only need to run through each story range once, you could go to the start of the story range first. And then, move the Selection to the start of the trailing whitespace after each match:<pre> Selection.HomeKey Unit:=wdStory
    Selection.Find.ClearFormatting
    With Selection.Find
    .Text = " ^p"
    .Forward = True
    .Wrap = wdFindContinue
    .MatchWildcards = False
    End With
    While Selection.Find.Execute
    Selection.Characters(1).Delete
    Selection.MoveStartWhile Cset:=" ", Count:=wdBackward
    Selection.Collapse (wdCollapseStart)
    Wend
    </pre>

    That macro should already fix the main document... For the rest, see the info in the FAQ article.

    <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16> Klaus

  15. #15
    3 Star Lounger rcbjr2's Avatar
    Join Date
    Jan 2001
    Location
    Matthews, NC
    Posts
    279
    Thanks
    6
    Thanked 1 Time in 1 Post

    Re: Find/Replace Special Characters (Word)

    Thanks for the new code. I know I have a problem with headers, etc., but I was ignoring those for now. I've seen the strings on working with all stories, and I've actually used some of that code in other macros. I wanted to make sure the code worked in the body first. I'll try your code later today and let you know how it works out.

    Thx.

    -Rich Belthoff

Page 1 of 3 123 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •