Results 1 to 12 of 12
  1. #1
    Star Lounger
    Join Date
    Nov 2003
    Posts
    61
    Thanks
    7
    Thanked 0 Times in 0 Posts

    VBA Symbols Replace (Word 2003/VBA Symbol Replace)

    I have some code that used to work that doesn't any more. It replaces two hyphens with mdashes, ellipsis with .<nonbreaking>.<nonbreaking>.<nonbreaking>., turns on smart quotes, etc. For some reason it has stopped working. Anybody know why and what I use instead?

    Thanks in advance for any help!

    -------------------------------


    Private Sub Clean()

    Home
    ActiveWindow.ActivePane.View.Type = wdMasterView

    With Selection.Find
    On Error Resume Next
    .Text = "^p^t"
    With .Replacement
    .Text = ""
    End With
    .Execute Format:=True, Replace:=wdReplaceAll
    End With

    Rem *** Replace double dash with true Mdash ***

    With Selection.Find
    On Error Resume Next
    .Text = " -- "
    With .Replacement
    .Text = "^+"
    End With
    .Execute Format:=True, Replace:=wdReplaceAll
    End With

    With Selection.Find
    On Error Resume Next
    .Text = "--"
    With .Replacement
    .Text = "^+"
    End With
    .Execute Format:=True, Replace:=wdReplaceAll
    End With

    Rem *** Change problem elipses into .hardspace. combination ***

    With Selection.Find
    On Error Resume Next
    .Text = "..."
    With .Replacement
    .Text = "." + Chr(9) + "." + Chr(9) + "."
    End With
    .Execute Format:=True, Replace:=wdReplaceAll
    End With

    With Selection.Find
    On Error Resume Next
    .Text = "

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

    Re: VBA Symbols Replace (Word 2003/VBA Symbol Replace)

    Does it help if you change Format:=True to Format:=False throughout the code?

  3. #3
    Star Lounger
    Join Date
    Nov 2003
    Posts
    61
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Re: VBA Symbols Replace (Word 2003/VBA Symbol Replace)

    It fixed the mdash replacement. (Thanks much!)

    The ellipsis/nonbreaking space replace still isn't functioning. It gives me "..." instead of ". . . " I've tried "^s" as to give me the nonbreaking space, but it doesn't work either.

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

    Re: VBA Symbols Replace (Word 2003/VBA Symbol Replace)

    I'm not sure what you're trying to do.

    With Replacement
    .Text = "." + Chr(9) + "." + Chr(9) + "."
    End With

    results in a period followed by a tab character, a period, a tab character and a period.

    If replacing 3 periods with an ellipsis is one of your AutoCorrect entries, this will interfere with trying to replace an ellipsis with three periods.

  5. #5
    Star Lounger
    Join Date
    Nov 2003
    Posts
    61
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Re: VBA Symbols Replace (Word 2003/VBA Symbol Replace)

    Right. I'm thinking I may have the character number incorrect for a non-breaking space. What I'm wanting is a nonbreaking space between the periods so it has spaces between the period, but will not break in the middle or have a period go to the next line.

    I need it to come out:

    <period><Nonbreaking Space><period><Nonbreaking Space><period>

    or

    ". . ."

    I'm getting:

    "..."

    I also tried "^s" and Chr(160) to get the nonbreaking space.

  6. #6
    5 Star Lounger kmurdock's Avatar
    Join Date
    Feb 2003
    Location
    Pacific Grove, California, USA
    Posts
    716
    Thanks
    10
    Thanked 34 Times in 28 Posts

    Re: VBA Symbols Replace (Word 2003/VBA Symbol Replace)

    In the past, I recorded a search and replace that put a non-breaking space into a name, then copied and pasted the space from my captured macro into another VBA routine. It didn't seem like it would work since the non-breaking space looked the same in my VBA code as the regular space. But when I copied and pasted it into my routine, it worked.

    Kim

  7. #7
    Star Lounger
    Join Date
    Nov 2003
    Posts
    61
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Re: VBA Symbols Replace (Word 2003/VBA Symbol Replace)

    This is my Find routine:

    ---------

    Private Sub Find(LookFor, wrp)
    On Error Resume Next
    Home
    Selection.Find.ClearFormatting
    With Selection.Find
    .Text = LookFor
    .Replacement.Text = ""
    .Forward = True
    If wrp = 0 Then .wrap = wdFindStop
    If wrp = 1 Then .wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    End With
    Selection.Find.Execute
    End Sub

    -------

    I also wondered if there wasn't some Autoformat option on that's giving me fits.

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

    Re: VBA Symbols Replace (Word 2003/VBA Symbol Replace)

    Either ".^s.^s." or "." & Chr(160) & "." & Chr(160) & "." should work. If they don't the Find text may be incorrect instead of the Replacement text, or the Find text doesn't occur in your document.

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

    Re: VBA Symbols Replace (Word 2003/VBA Symbol Replace)

    Check whether the "three periods" to "ellipsis" replacement is in your AutoCorrect list.
    And whether the "Straight quotes" with "Smart quotes" check box is ticked in the AutoFormat As You Type tab of Tools | AutoCorrect Options.

  10. #10
    Star Lounger
    Join Date
    Nov 2003
    Posts
    61
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Re: VBA Symbols Replace (Word 2003/VBA Symbol Replace)

    No "three periods" or iteration like it in the AutoCorrect list.

    The "Straight quotes with Smart Quotes" is checked. I do have it changing them from straight to smart and that does function for me.

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

    Re: VBA Symbols Replace (Word 2003/VBA Symbol Replace)

    Could you attach a document with

    a) the macro(s)
    [img]/forums/images/smilies/cool.gif[/img] some examples of text that should be replaced by the macro(s) but that is left unchanged?

  12. #12
    Star Lounger
    Join Date
    Nov 2003
    Posts
    61
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Re: VBA Symbols Replace (Word 2003/VBA Symbol Replace)

    Hey Hans! I just found it. This bit of code just after the replacement for the ellipsis was what was causing it:

    ----

    Rem hard spaces.
    Rem *** searches for 4 spaces at beginning of line and deletes them ***
    With Selection.Find
    On Error Resume Next
    .Text = Chr$(160)
    With .Replacement
    .Text = ""
    End With
    .Execute Format:=True, Replace:=wdReplaceAll
    End With
    -----

    Thanks so much for your help. Both of you! [img]/forums/images/smilies/smile.gif[/img]

Posting Permissions

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