This macro converts titled hyperlinks in a Word document into Lawlift’s ::url[...] syntax so both the title and the URL survive the import.

Lawlift offers you the possibility to format a URL inserted as a hyperlink with a title using the “title(…)” function. We have shown you here exactly how this works.

However, if you have a Word document in advance that is to be automated and already contains such formatted links, copying the text into Lawlift directly would keep only the titles, not the URLs.

A macro can help here, which converts all formatted links in the Word document into the form “::url[www.exampleurl.de title(example)]” readable by Lawlift. Afterward, the formatted links can simply be copied from the Word file into the Lawlift template. Lawlift recognizes the expressions and inserts them as clickable URLs with the given title, as shown in our help.

Unformatted links can also be simply copied into the Lawlift template without using this macro and Lawlift recognises them as such.

Here is an example of a macro that prepares the source file for import into Lawlift:

Sub Format_Hyperlinks()
 Dim Link As Hyperlink
 Dim HTP1, HTP2 As Integer
HTP1 = 0
HTP2 = 0
 'checking document if it contain URLs
 If ActiveDocument.Hyperlinks.Count > 0 Then
 For Each Link In ActiveDocument.Hyperlinks '------------------------
 If Link.Address <> "" Then
 'links vs bookmarks
 If InStr(Link.Address, "http") > 0 Then '------------
 Link.Range.Select
 'checking for address only links
 If Link.TextToDisplay = Link.Address Then
 Selection.TypeText "::url[" & Link.Address & "]"
 HTP1 = HTP1 + 1
 Else 'if link have a text to display
 Selection.TypeText "::url[" & Link.Address & " Title(" & Link.TextToDisplay & ")]"
 HTP2 = HTP2 + 1
 End If
 End If '------------
 End If
 Next Link '------------------------
 'statistic message
 mSg = "There are " & HTP1 & " link(s) without Title." & Chr(13) & "There are " & HTP2 & " link(s) with Title." & Chr(13) & "Total " & HTP1 + HTP2 & " link(s) formatted so far."
 MsgBox mSg, vbOKOnly + vbInformation, "Statistics"
 Else
 'if not links were found in document
 MsgBox "There are no hyperlinks in this document."
 End If
End Sub
Sub Format_Hyperlinks_Updated()
'------------------------------------------------'
'--------- Dealing Hyperlinks in Body -----------'
'------------------------------------------------'
 Dim Link As Hyperlink
 Dim HTP1, HTP2 As Integer
HTP1 = 0
HTP2 = 0
BD = 0
FT = 0
 'checking document if it contain URLs
On Error Resume Next ' Handling unknown error for this time only
 If ActiveDocument.Hyperlinks.Count > 0 Then
 For Each Link In ActiveDocument.Hyperlinks '------------------------
 'links vs bookmarks
 If InStr(Link.Address, "http") > 0 Then '------------
 Link.Range.Select
 'checking for address only links
 If Link.TextToDisplay = Link.Address Then
 Selection.TypeText "::url[" & Link.Address & "]"
 HTP1 = HTP1 + 1
 Else 'if link have a text to display
 Selection.TypeText "::url[" & Link.Address & " Title(" & Link.TextToDisplay & ")]"
 HTP2 = HTP2 + 1
 End If
 End If
 BD = BD + 1
 Next Link '------------------------
 Else
 'if not links were found in document
 MsgBox "There are no hyperlinks in the body of document."
 End If
'------------------------------------------------'
'------- Dealing Hyperlinks in Footnotes --------'
'------------------------------------------------'
Dim h As Hyperlink
With ActiveDocument
If .Footnotes.Count >= 1 Then
 With .StoryRanges(wdFootnotesStory)
 For Each h In .Hyperlinks
 If InStr(h.Address, "http") > 0 Then
 h.Range.Select
 'checking for address only links
 If h.TextToDisplay = h.Address Then
 Selection.TypeText "::url[" & h.Address & "]"
 HTP1 = HTP1 + 1
 Else 'if link have a text to display
 Selection.TypeText "::url[" & h.Address & " Title(" & h.TextToDisplay & ")]"
 HTP2 = HTP2 + 1
 End If
 End If
 FT = FT + 1
 Next h
 End With
End If
End With
'------ Statistic Message -------'
 mSg = "Number of Hyperlink(s) in:" & Chr(13) & "Main Document =" & BD & Chr(13) & "Footnote =" & FT & Chr(13) & Chr(13) & "There are " & HTP1 & " link(s) without Title." & Chr(13) & "There are " & HTP2 & " link(s) with Title." & Chr(13) & Chr(13) & "Total " & HTP1 + HTP2 & " link(s) formatted so far."
 MsgBox mSg, vbOKOnly + vbInformation, "Statistics"
End Sub

Note: Only run the macro once, otherwise the functions will nest inside each other.

Run the macro: see How to insert and run a Word macro.