Makros für Microsoft Word

URL ohne Trennstrich automatisch umbrechen lassen

Folgendes Makro fügt zwischen sämtliche Zeichen des ausgewählten Texts bedingte Nullbreite-Wechsel ein. Word kann den ausgewählten Text dann an jeder Stelle in eine neue Zeile umbrechen und fügt bei einem Umbruch keinen Trennstrich ein. Ist kein Text ausgewählt, wird an der aktuellen Cursorposition ein bedingter Nullbreite-Wechsel eingefügt.

Sub urlBreaker()
'
' urlBreaker Makro
'
' by Fabian Haibl
'
' Version 0.3
'
Dim uri
Dim text
Dim hyperlinkscount

If Selection.Type = wdSelectionIP Then
Selection.InsertAfter (ChrW(8204))
Exit Sub
End If

text = Selection.text
hyperlinkscount = Selection.Hyperlinks.Count

If hyperlinkscount < 0 Or hyperlinkscount > 1 Then
MsgBox "Selection may only contain zero or one hyperlink.", vbCritical
Exit Sub
End If
If hyperlinkscount = 1 Then
uri = Selection.Hyperlinks.Item(1).Address
End If
For i = Len(text) - 1 To 1 Step -1
text = Left(text, i) & ChrW(8204) & Right(text, Len(text) - i)
Next
If hyperlinkscount = 1 Then
ActiveDocument.Hyperlinks.Add Selection.Range, uri, , uri, text
Else
Selection.text = text
End If
End Sub