By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,988 Members | 1,493 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,988 IT Pros & Developers. It's quick & easy.

vBA : Replace Function

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

Expand|Select|Wrap|Line Numbers
  1.  H = Selection.Text
  2.  K = Replace(H, " ", "")
  3.  
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
Nov 28 '07 #1
Share this Question
Share on Google+
4 Replies


Expert 5K+
P: 8,434
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.
Nov 29 '07 #2

P: 1
Just a guess, but did you try entering the ASCII code for the space character...?

eg. K = replace (H, chr(32),"")
Mar 17 '08 #3

P: 11
If all else fails, create a new string from the old string one character at a time.

Bobby
Mar 20 '08 #4

Expert 5K+
P: 8,434
I'd love to know how this turned out, but according to his/her profile EByker hasn't been on for almost a month.
Mar 20 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.