Merging Zotero Citations in Word

A few years ago, a PI introduced me to the free citation manager Zorero and have really grown to love it. Although, while working with it for a while i did come a cross a few features that are missing and would make working with it much more efficient especially when writing manuscripts with multiple authors.

One of the features that i was missing the most, was the ability to merger citations in the text as you rearranged the text, without having to manually add the citations one by one from one field to the other.

To solve this problem, i found a very simple VB macro deep in some Zotero Forums, which I have found to work beautifully.

While working in a Word Document with Zotero simply hold and press Alt+F11 (Mac Users will have to figure this one out on their own) to open up the Visual Basics panel. Then in the main bar under Insert, select Module.

Paste the following text in the window that opens:

Sub ZoteroJoinCitations()

Dim MyField As Field
Dim MyRg As Range
Dim IStrt, ILen, IEnd As Long
Dim First As Boolean
Dim FOrig, FContent, FRest, FNew As String
FContent = “”
First = True
Set MyRg = Selection.Range

For Each MyField In MyRg.Fields
If InStr(1, MyField.Code.Text, “ADDIN ZOTERO_ITEM CSL_CITATION”, vbTextCompare) = 2 Then
If First Then
FOrig = MyField.Code.Text
IEnd = InStr(1, MyField.Code.Text, “],””schema””:”, vbTextCompare) – 1
First = False
Else
IStrt = InStr(1, MyField, “””citationItems””:[“, vbTextCompare) + 17
ILen = InStr(1, MyField, “],””schema””:”, vbTextCompare) – IStrt
FContent = FContent & “,” & Mid(MyField.Code.Text, IStrt, ILen)
End If
End If
Next MyField

ILen = Len(FOrig) – IEnd
FNew = Left(FOrig, IEnd) & FContent & Right(FOrig, ILen)
‘ MyRg.Fields(1).Code.Text = FNew
‘ 2018-03-08 commented out
‘ would insert the Zotero field contents in the first field of the selection
‘ even if this is not a Zotero field

First = True
For Each MyField In MyRg.Fields
If InStr(1, MyField.Code.Text, “ADDIN ZOTERO_ITEM CSL_CITATION”, vbTextCompare) = 2 Then
If First Then
MyField.Code.Text = FNew ‘ 2018-03-08 inserted here
First = False
Else
MyField.Delete
End If
End If
Next MyField
End Sub

Now go back into your document and select the references you wish to combine. Once selected, jump back into the macro interface and press the green play button in the menu bar. Your references are now merged.

As you may notice when looking back at you document, some of the fused references appear to be missing. Don’t worry, they are not. Word just needs to reprocess the information. To display your fused references correctly, simply refresh your Zoter references. Et voilĂ !

Have fun!

Leave a Comment