Consulting

Results 1 to 6 of 6

Thread: Solved: Find/Replace with Return Character

  1. #1
    Site Admin
    The Princess
    VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location

    Solved: Find/Replace with Return Character

    I have a macro that inserts the ? character:

    [vba]Selection.InsertSymbol CharacterNumber:=182, Unicode:=True, Bias:=0[/vba]

    What I need is to find the real paragraph return, and replace it with this character AND a paragraph return. Here's the code I'd use to find a real paragraph return and replace it with an "X" and the real paragraph return:


    [vba]Sub Macro3()
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
    .Text = "^p"
    .Replacement.Text = "X^p"
    .Forward = True
    .Wrap = wdFindContinue
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    End Sub[/vba]


    I am working on a book with code in it. I want to display to the reader where they must enter paragraph returns. My alternative is to type in so many underscores to make the code fit all within this 4-inch wide page.


    Help me, help me!
    ~Anne Troy

  2. #2
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    Hi Anne,

    Just change:
    [vba].Replacement.Text = "X^p"[/vba]
    To
    [vba].Replacement.Text = Chr(182) & "^p"[/vba]
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  3. #3
    Site Admin
    The Princess VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    Yay!!
    Thanks, Tony!!
    ~Anne Troy

  4. #4
    Site Admin
    The Princess VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    You know, Tony.... about half the time I run this dang macro, it replaces all of them--not just the selection. Is that bizarre or what? I just undo and do it again and again until it just does the selection. I don't get it. Word 2000.
    ~Anne Troy

  5. #5
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    Try changing
    [VBA].Wrap = wdFindContinue[/VBA]
    to
    [VBA].Wrap = wdFindStop[/VBA]
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  6. #6
    Site Admin
    The Princess VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    k. thanks!
    ~Anne Troy

Posting Permissions

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