An MS Word macro that links Zotero author-date or numeric style citations to their bibliography entry. This project was inspired by discussions of Word: Possibility to link references and bibliography in a document?
- The script automatically detects whether the citation style used in the document has been supported.
- More than 10 citation styles have been tested, see the list of Supported Citation Styles.
- The Zotero fields are preserved after linking to the bibliography.
- Allows setting a unified Word text style for newly established links, enabling changes to the link's color, size, font, etc.
- Correctly handles multiple references in the Author-Date style where the first author is the same.
Numeric example:
Author-year example:
Author-year example (only the year part is linked):
Caution
Before running the ZoteroLinkCitationAll
macro, please ensure you have backed up your document. The operations performed by this script are bulk actions that are irreversible. A backup ensures that you can restore your original document in case anything does not go as expected.
This guide is aimed at beginners and provides detailed instructions on importing and running the ZoteroLinkCitation.bas
script in Microsoft Word.
- Microsoft Word (2016 or later recommended for compatibility).
- The
ZoteroLinkCitation.bas
file.
- Open Microsoft Word.
- Press
Alt
+F11
to open the Visual Basic for Applications (VBA) Editor.
- Within the VBA Editor, locate
Normal
in the Project window on the left. Right-click onNormal
chooseImport File...
. - Locate and select your
ZoteroLinkCitation.bas
file, then clickOpen
to import the script.
- Exit the VBA Editor to return to your Word document.
- Save your document as a Macro-Enabled Document (
.docm
):- Click
File
>Save As
. - Select your desired location.
- Choose
Word Macro-Enabled Document (*.docm)
from the "Save as type" dropdown. - Click
Save
.
- Click
Adjust Word’s macro settings to allow the macro to run:
- Go to
File
>Options
>Trust Center
>Trust Center Settings...
>Macro Settings
. - Select
Disable all macros with notification
for security while enabling functionality. - Click
OK
to confirm.
- Make the
Developer
tab visible in Word (if it’s not already):- Navigate to
File
>Options
>Customize Ribbon
. - Ensure
Developer
is checked on the right side, then clickOK
.
- Navigate to
- Click
Macros
in theDeveloper
tab. - Find and select
ZoteroLinkCitationAll
from the list, then clickRun
.
Press Alt
+ F8
, find and select ZoteroLinkCitationAll
from the list, then click Run
.
- Click
File
>Options
>Quick Access Toolbar
. - In the
Choose commands from list
, clickMacros
. - Select the macro
ZoteroLinkCitationAll
. - Click
Add
to move the macro to the list of buttons on theQuick Access Toolbar
.
The ZoteroLinkCitationAll
macro opens a dialog that allows you to set a uniform Word text style for newly created hyperlinks, which can change the color, size, font, etc. of the hyperlink.
- Macro Security: Only run macros from trusted sources. Macros can contain harmful code.
- Testing: Consider running the macro on a non-critical document first to familiarize yourself with its effects.
Manually creating hyperlinks in citations or removing brackets can cause an error of Subscript out of range
If you create hyperlinks in citations or remove brackets manually, you may get an error called Subscript out of range
. ZoteroLinkCitation
relies on brackets []
or ()
to recognize the boundary of Zotero citations, and match each citation in the field to their CSL data by text parsing. So please revert to the original state before using ZoteroLinkCitation
, if these changes already exist in your document.
This type of mismatch only occurs among different citations within the same field in Word documents and is prone to happen when your document switches between the Author-Date and Numeric styles.
The solution is to locate all fields with mismatched citations and use the Zotero Word plugin to edit each field. Repeatedly check/uncheck the Keep Sources Sorted
option in the dropdown menu of the Zotero dialog to update the order of citation objects, thus matching the actual order of citation text in the Word document. After updating all problematic fields, rerun the ZoteroLinkCitationAll
macro.
Why does this situation occur? It's because ZoteroLinkCitation
relies on the order of citations within a field, fetching the citation titles from the CSL JSON data contained in that field, and then establishing the link between citations and the bibliography.
This problem is nearly impossible to resolve with VBA scripts, and currently, there is no method found to force Zotero to update the order of citation objects in the CSL JSON data across all fields.
- American Political Science Association †
- American Psychological Association (APA) 7th edition †
- American Sociological Association 6th/7th edition †
- Chicago Manual of Style 17th edition (author-date)
- China National Standard GB/T 7714-2015 (author-date) †
- Cite Them Right 12th edition - Harvard †
- Elsevier - Harvard (with titles)
- Molecular Plant
† In these citation styles, only the year part is linked to the bibliography by default. You can change this default behaviour by manually modifying the parameter onlyYear
in the script.