How to make urls (and delimiters such as \, /, : and @) wordwrap in Word

Or: How to insert a zero-width space in your documents

Article contributed by Klaus Linke and Dave Rado

Many delimiter characters, such as the forward slash used in urls and the backslash used in file paths, don't wordwrap in Word, although in most cases one would want them to.

Fortunately, in Word 2000 and above, you can make them wrap by inserting a zero-width space character (Unicode character 200B, decimal 8203) immediately after the delimiter character. Unfortunately, the zero-width space character is not supported in Word 97. If you open a document containing zero-width spaces in Word 97, they will display and print as small empty boxes; so the following is really only useful if you will not be sending Word documents to Word 97 users. You could get round this problem by distributing Word 2000+ documents  in PDF format, however – the PDFMaker macro copes without any glitches; the hyperlinks it creates in the PDF preserve their wordwrap while still working as hyperlinks.

Note that if you want to insert a zero-width space into a hyperlink, you must create the hyperlink first, and then insert the zero-width spaces afterwards – otherwise the hyperlink won't work (won't be valid).

If you have non-printing characters displayed, the zero-width space displays as a bordered box likethis.

Unfortunately, you can't access the zero-width space character via Insert + Symbol + Special Characters, which is worth contacting http://support.microsoft.com/contactus/ about. However, there are a number of ways of inserting a zero-width space character:

1.

Assign the following macro to a keyboard shortcut or toolbar button

Sub InsertZeroWidthSpace()
    Selection.InsertAfter ChrW(8203)
    Selection.Collapse Direction:=wdCollapseEnd
End Sub

2.

Select Insert Symbol, choose a big Unicode font like Arial Unicode MS, and go to the subset General Punctuation. Click on the 12th space character (empty box); the Code 200B should appear in the status bar of the document. Define a keyboard shortcut for that character in the same dialog (Note: You don't really need a big font for this character; unfortunately, it just doesn't show up in the InsertSymbol dialog for smaller fonts).

3.

If you are using Word 2000, you can type Alt-8203 in any dialog box, (you have to type the numbers using the numeric keypad; if you don't have one, you can't use this method); cut the character with Ctrl-X and paste it into the text with Ctrl-V.

4.

If you are using Word 2002, you can type 200B in the document and press Alt+X.

5.

You can create AutoCorrect entries for any characters that you always (or almost always) want to be followed by a zero-width space, so that they will word-wrap. But beware – it would be very dangerous to use this method for characters that you use in urls or email addresses, such as backslash or forward slash characters, because if you do that, you will create invalid hyperlinks (unless you have switched off Replace internet and network paths with hyperlinks under Tools + AutoCorrect + AutoFormat As You Type). For characters used in urls you will need to use one of the other methods.

If you want to create such an AutoCorrect entry – for example, if you want all your underscores to be automatically followed by a zero-width space – insert an underscore in your document, followed by a zero-width space: _. Select both characters and choose Tools + Autocorrect. The right-hand side of the dialog (where it says With) will be automatically filled in. Don't worry about the fact that the space doesn't display correctly in the dialog – it will insert correctly. In the left hand side of the dialog (where it says Replace) type an underscore. Click OK. From now on, wherever you type an underscore, a zero-width space will be inserted as well.

6.

You can create AutoText entries; the procedure is more or less the same as creating AutoCorrect entries, and it's less risky (but less convenient).

7.

Alternatively, you could do a Find and Replace with wildcards. For instance, the following macro will add a zero-width space after any forward slashes or backslashes that are preceded and followed by an alphabetic or numeric character (so it will leave http:// alone, for instance, and it won't insert doubled-up zero-width spaces if run multiple times):

Sub InsertZeroWidthSpaceAfterSlashes()

With Selection.Find
   .ClearFormatting
   .Replacement.ClearFormatting
   .Forward = True
   .Format = False
   .MatchCase = False
   .MatchWholeWord = False
   .MatchWildcards = True
   .MatchSoundsLike = False
   .MatchAllWordForms = False

   .Wrap = wdFindContinue
   .Text = "([a-zA-Z0-9]/)([a-zA-Z0-9])"
   .Replacement.Text = "\1" & ChrW(8203) & "\2"
   .Execute Replace:=wdReplaceAll

   .Wrap = wdFindContinue
   .Text = "([a-zA-Z0-9][\\])([a-zA-Z0-9])"
   .Replacement.Text = "\1" & ChrW(8203) & "\2"
   .Execute Replace:=wdReplaceAll

    'Clear the settings again
   .Text = ""
   .Replacement.Text = ""
   .MatchWildcards = False

End With

End Sub

Note; If doing the Replace manually use ^u8203 rather than ChrW(8203).

For many more examples of wildcard searches, and for in-depth coverage of how to use wildcards, see: Finding and replacing characters using wildcards.

Some gotchas

1.

As mentioned previously, if a document containing zero-width spaces is opened in Word 97, they will display and print as small empty boxes. You can get round this by distributing Word documents in PDF format; 

2.

If you paste into Notepad the space disappears. If you paste into any application As Text, the space also disappears. If you copy text containing the zero-width space and paste as Unformatted Unicode Text in Word 2000+, the character is also lost (this is a bug, and worth contacting http://support.microsoft.com/contactus/ about).

If you paste As Rich Text into an application that supports Unicode (such as Publisher) the zero-width space remains a zero-width space.

But if you paste (or import) as rich text into any rich-text-supporting application that doesn't support Unicode (such as CorelDraw or PageMaker) you get either a square box or a question mark (depending on the application) – but that happens with any upper Unicode characters you use, not just this one.

3.

A search for some/text will not find some/text. You can get round that by searching for some/^?text” (or some/?text”, with wildcards switched on).

It would be nice if the zero-width-space could be  ignored when you do a Find and Replace (just as optional hyphens are); this is also well worth contacting http://support.microsoft.com/contactus/ about.


Click to view Terms of Use page

Click to view Disclaimer page