Word
top of page

In the past I have posted about using vba code to automatically add hyperlinks into a Word document. The Tip of the Night for May 25, 2015 discussed how to add urls with a Visual Basic macro (to files saved on a network drive or a web address) after marking citations in the document in XE codes using the auto mark function. This code did not however work for citation references made in footnotes. The Tip of the Night for May 26, 2015 discussed a workaround using an add-in for MS Word called NoteStripper which converts footnotes to endnotes. The vba code works on the endnotes, which NoteStripper could then convert back to footnotes. However, formatting irregularities in the footnotes can prevent NoteStripper from reconverting the notes, and even when the reconversion worked, it was still necessary to carefully confirm that they were all placed back in the same spots in the document. However, the code works well in the body of a Word document, and in 2017 I posted a YouTube video describing the process.


I am now able to pass along an updated version of the vba code which will add links to both the body of a Word document and its footnotes at the same time without the need to bother with the often cumbersome process of converting the footnotes to endnotes, and reconverting them back again. Oscar Sun posted a response to my inquiry for a solution on stackoverflow.


The below visual basic code works the same way as the code discussed back in May 2015, converting urls added to XE codes to hyperlinks - but this version processes both the body and the footnotes at the same time. The steps can be followed in the below animated gif.


The key to editing the vba code is to enter the full path to the folder containing the documents you are linking to with only the first letter of that folder on the line of code beginning: If Left$(url, 4) = "

. . . change the 4 to the character count for that truncated path. So for example:

If Left$(url, 14) = "C:\foofolder\e" Then

. . . because 'C:\foofolder\e' is 14 characters long.

On the next line you want to account for how many words are used in the citations you are linking to. In this case since each citation is two words, 'Exhibit 01'; 'Exhibit 02', etc., we enter:

isHyper = 2




That's it. So long as you can generate a list of the citations in your brief or expert report and put them in a table with the corresponding PDFs you're linking to, you can automatically add 10 or 10,000 hyperlinks in your Word document.


Sub MakeHyperlinks() Dim afield As Field Dim url As String Dim isHyper As Integer Dim sr As Range For Each sr In ActiveDocument.StoryRanges 'For Each afield In ActiveDocument.Fields For Each afield In sr.Fields If afield.Type = wdFieldIndexEntry Then isHyper = 0 afield.Select Selection.Collapse url = Right$(afield.Code, Len(afield.Code) - 5) url = Left$(url, Len(url) - 2) If Left$(url, 4) = "../F" Then isHyper = 1 End If If Left$(url, 4) = "../T" Then isHyper = 2 End If If isHyper <> 0 Then Selection.MoveStart unit:=wdCharacter, Count:=-3 Selection.MoveStart unit:=wdWord, Count:=-isHyper afield.Delete ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, _ Address:=url End If End If Next afield Next sr End Sub




The Tip of the Night for May 5, 2019 discussed hyphen-minuses, which look similar to hyphens but which are not actually the same character and will not be interpreted as such by Excel, Relativity, and other applications.


When parsing out Bates numbers to review, or just finalizing the Word version of a brief to be filed, you should also be on the lookout for non-breaking hyphens. In this example, we have two phrases which both contain dashes that, to the naked eye, appear to be the same character.


If you search for a hyphen in Word, it will find them both. However, if the same text is copied into NotePad:


. . . the dash in the first phrase disappears. If you copy the text into Excel you can see a small difference:



The dash in the second phrase is a little shorter and thicker. The Excel UNICODE formula for the dash from the first phrase shows its alt code to be 8209 - different from the alt code for a hyphen-minus, which is 0045, and different from a standard hyphen (alt code 8208).



It can't be a hyphen because Excel will not let the first character in a cell be a hyphen.


The dash from the first phrase is a non-breaking hyphen ‑ . These can be located in Word by searching: ^~

. . . in Find:



This search in Word will find nonbreaking hyphens but not hyphen-minuses, hyphens, en dashes, em dashes. The purpose of the nonbreaking hyphen is to keep words with hyphens from being separated onto different lines. The second sentence here uses a nonbreaking hyphen:



But they certainly make life difficult for those of us who want to do things like copy out and parse dozens of references to trial exhibit numbers which contain dashes (e.g., PX-1278, DX-217, etc.) and run searches on them.








If you want help getting a list of last names or other proper nouns which may be keywords in a long text excerpt, you can make use of the below Visual Basic macro which will generate a list of words that MS Word will identify as possible spelling errors.


If you simply plug in the code in a new module in Visual Basic:



. . . the macro will review a Word document:




. . . and output a list of the words which are not in the spell check dictionary:



Thanks to Jay Freedman for posting this macro here. [Copy the text from the post on the Microsoft site, or remove the extra blank lines that result when you paste this code into Visual Basic to make it work.]


Sub ListSpellingErrors()

Dim inDoc As Document

Dim outDoc As Document

Dim er As Range

Set inDoc = ActiveDocument

If ActiveDocument.SpellingErrors.Count > 0 Then

Set outDoc = Documents.Add

outDoc.Sections(1).Headers(wdHeaderFooterPrimary) _

.Range.Text = "Spelling errors in " & inDoc.FullName

Else

MsgBox "There are no spelling errors in this document."

Exit Sub

End If

For Each er In inDoc.SpellingErrors

outDoc.Range.InsertAfter er.Text & vbCr

Next er

' optionally, to sort the output,

' remove the quote mark from the next line

' outDoc.Range.Sort

End Sub





Sean O'Shea has more than 20 years of experience in the litigation support field with major law firms in New York and San Francisco.   He is an ACEDS Certified eDiscovery Specialist and a Relativity Certified Administrator.

​

The views expressed in this blog are those of the owner and do not reflect the views or opinions of the owner’s employer.

​

If you have a question or comment about this blog, please make a submission using the form to the right. 

Your details were sent successfully!

© 2015 by Sean O'Shea . Proudly created with Wix.com

bottom of page