Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-02-2018, 10:48 AM
Chayes Chayes is offline VBA Insert spaces between each character... Windows XP VBA Insert spaces between each character... Office 2003
Advanced Beginner
VBA Insert spaces between each character...
 
Join Date: May 2012
Posts: 79
Chayes is on a distinguished road
Default VBA Insert spaces between each character...

Hi All




I'm trying to insert hard spaces into some text in a Word Document.


This would mean that after running the code on the selected text ,


Hello There!


would become


H e l l o T h e r e !




including a double space between the words.

Can someone advise with some code , please?




Grateful for any help.

Last edited by Chayes; 07-02-2018 at 10:50 AM. Reason: add additional text
Reply With Quote
  #2  
Old 07-02-2018, 03:16 PM
macropod's Avatar
macropod macropod is offline VBA Insert spaces between each character... Windows 7 64bit VBA Insert spaces between each character... Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,371
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

You don't need a macro for that - a simple Find/Replace will do the job, where:
Find = ^?
Replace = ^&^32
or:
Find = ^?
Replace = ^&^160
the latter will help keep words together.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 07-02-2018, 03:46 PM
slaycock slaycock is offline VBA Insert spaces between each character... Windows 7 64bit VBA Insert spaces between each character... Office 2016
Expert
 
Join Date: Sep 2013
Posts: 255
slaycock is on a distinguished road
Default

Depending on why you wish to add such spacing you might also consider the font spacing which might be easier to manage in the long term.

e.g. Try increasing the font spacing to 5 pt for a section of text. This gives the appearance of adding spaces between characters.
Reply With Quote
  #4  
Old 07-02-2018, 04:00 PM
macropod's Avatar
macropod macropod is offline VBA Insert spaces between each character... Windows 7 64bit VBA Insert spaces between each character... Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,371
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by slaycock View Post
This gives the appearance of adding spaces between characters.
It also has the advantage of not unnecessarily breaking words for line-wrapping purposes.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 07-02-2018, 04:16 PM
Chayes Chayes is offline VBA Insert spaces between each character... Windows XP VBA Insert spaces between each character... Office 2003
Advanced Beginner
VBA Insert spaces between each character...
 
Join Date: May 2012
Posts: 79
Chayes is on a distinguished road
Default

Hi


Ok thanks for this. I find



Find = ^?
Replace = ^&^32


works fine. It inserts a hard space between each letter in a word , which is exactly what I was looking for.


Curiously , where a space exists say between two words in a phrase , it makes this into 3 spaces rather than the expected 2. Easily remedied with another search / replace , but I thought you'd like to know.


Thanks for your help - much appreciated.
Reply With Quote
  #6  
Old 07-02-2018, 04:56 PM
macropod's Avatar
macropod macropod is offline VBA Insert spaces between each character... Windows 7 64bit VBA Insert spaces between each character... Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,371
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

The Find/Replace inserts a space after every character - including spaces. So, if you replace a letter followed by a space with those characters and spaces, you'll end up with a letter followed by three spaces.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #7  
Old 07-02-2018, 05:12 PM
Chayes Chayes is offline VBA Insert spaces between each character... Windows XP VBA Insert spaces between each character... Office 2003
Advanced Beginner
VBA Insert spaces between each character...
 
Join Date: May 2012
Posts: 79
Chayes is on a distinguished road
Default

Yes , I can see how that works. As I was saying , It's relatively easily remedied with another search/replace , but it's a pity it can't be done on first application. At any rate , thanks again for your help.




Reply With Quote
  #8  
Old 07-02-2018, 05:59 PM
macropod's Avatar
macropod macropod is offline VBA Insert spaces between each character... Windows 7 64bit VBA Insert spaces between each character... Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,371
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

You could use a wildcard Find/Replace, where:
Find = [! ]
Replace = ^&^32
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #9  
Old 07-03-2018, 12:45 AM
Chayes Chayes is offline VBA Insert spaces between each character... Windows XP VBA Insert spaces between each character... Office 2003
Advanced Beginner
VBA Insert spaces between each character...
 
Join Date: May 2012
Posts: 79
Chayes is on a distinguished road
Default

Yes , that's got it. Perfect first time. Many thanks for your help.


Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA Insert spaces between each character... How to insert paragraph character after every 500 characters? aditya_bokade Word VBA 28 11-13-2021 10:48 PM
VBA Insert spaces between each character... Find and Replace/Insert 'CR', delete leading Spaces wherever a user Clicks in a Word document DavidL Word VBA 7 04-04-2018 12:01 AM
Detecting that previous character doesn't exist (i.e., present character is first in document) Robert K S Word VBA 15 08-01-2016 09:33 AM
VBA Insert spaces between each character... macro to find a character and insert space so autocorrect will expand redzan Word VBA 3 05-22-2014 04:22 PM
Office 2010 - insert character after each line. Ernst-Emil Word 7 08-15-2012 09:13 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:46 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft