Results 1 to 3 of 3
  1. #1
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    When CHR$(160) = CHR$(032) (word97/sr2)

    Here's something else I don't understand about Word97/VBA:


    The cheap'n'nasty cobbled together from a recorded macro attempts to locate strings such as "30 metres" and change the regular spacebar space (ASCII(032)) into a hard space (ASCII(160)). (but see especially this post.)



    The macro appears to succeed, in that subsequent inspection (using a display-code macro) shows that the CHR$(160) has been effected.

    However, re-running the macro sees it re-visting all the old sites. It is as if the regular find-and-replace code supplied by MSWord treates CHR$(160 as a CHR$(32)


    <pre>Sub HardSpaces()

    Selection.Find.ClearFormatting

    With Selection.Find
    .Text = "^#" & Chr$(32) & "^$"
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    End With

    While Selection.Find.Execute
    Dim strText As String
    strText = Selection.Text
    Selection.TypeText (Left$(strText, 1) & Chr$(160) & Right$(strText, 1))
    Wend

    End Sub
    </pre>


  2. #2
    2 Star Lounger
    Join Date
    Feb 2001
    Location
    Wellington, New Zealand
    Posts
    143
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: When CHR$(160) = CHR$(032) (word97/sr2)

    Could you instead use "[0-9]^0032?", with wildcards, for your subsequent checking? This does seem different from "[0-9]^0160?".

  3. #3
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: When CHR$(160) = CHR$(032) (word97/sr2)

    Thanks, William. Yes, this does the trick (for me, at least - a re-run of the macro now skips over previously changed spaces).

    I'm puzzled now by a different thing: Why this works and my original didn't.

    In both cases there's a "32" being replaced by a "160", but in your case

    1) You are using a range of digits rather a mask for the first of three characters
    2) You are using a four-digit character code rather than a three-digit code
    3) You specify any character rather than a letter for the third and final character
    4) You specify wildcards.

    Not big issues because, thanks again, the macro does its job and I can get on with life.

    I do have to learn a bit more about codes and wildcards, though; I can see that!

Posting Permissions

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