PDA

View Full Version : Non-Breaking spaces for VBA string



Gavint
07-24-2006, 12:08 AM
Is there a way to format text in a VBA string to ensure that spaces are all non-breaking?

I have dates (long format), that are dropped from a database into form fields (or bookmarks) in Word. My problem is that sometimes if the date is near the end of a line, parts of the date may drop to the next line. For style guidelines, I need to ensure that the spaces in the date are non-breaking (ie all text stays together on the same line).

Thanks in advance.

TonyJollans
07-24-2006, 09:30 AM
In a String in VBA, use Replace ...
strDate = Replace(strDate, Chr$(32), Chr$(160))
In a Document use Find and replace ...
ActiveDocument.Bookmarks(1).Range.Find.Execute _
Findtext:=Chr$(32), _
ReplaceWith:=Chr$(160), _
Replace:=wdReplaceAll
.. or ..
ActiveDocument.Bookmarks(1).Range.Find.Execute _
Findtext:=" ", _
ReplaceWith:="^s", _
Replace:=wdReplaceAll

mdmackillop
08-13-2006, 03:45 AM
Hi Tony,
Is there a keyboard combination for this, other than Ascii?
Regards
MD

TonyJollans
08-17-2006, 11:44 AM
Hi Malcolm,

Keyboard combination for what? Non-breaking space (Ctrl+Shift+Space) or the F&R (none)?

mdmackillop
08-17-2006, 11:46 AM
The former. Thank you.