vBA : Replace Function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • EByker
    New Member
    • Apr 2007
    • 18

    vBA : Replace Function

    I want to remove all the blanks from a selected string in Word, using the following:

    Code:
     H = Selection.Text
     K = Replace(H, " ", "")
    Replace seems not to recognise the blanks, and returns a string with the blanks still there (i.e. K=H) which is not what is intended.

    Any suggestion how I can fix this, please!

    Thanks

    B
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #2
    Not that familiar with VBA, but the Replace function should work. Are you sure those "spaces" aren't actually some invisible character? Or perhaps, say, non-breaking spaces? Try checking their ASCII value.

    Comment

    • reddigari
      New Member
      • Mar 2008
      • 1

      #3
      Just a guess, but did you try entering the ASCII code for the space character...?

      eg. K = replace (H, chr(32),"")

      Comment

      • bobbystrain
        New Member
        • Sep 2007
        • 11

        #4
        If all else fails, create a new string from the old string one character at a time.

        Bobby

        Comment

        • Killer42
          Recognized Expert Expert
          • Oct 2006
          • 8429

          #5
          I'd love to know how this turned out, but according to his/her profile EByker hasn't been on for almost a month.

          Comment

          Working...