Trigger Word macro on creating/modifying cite field

edited August 11, 2018
Whenever Zotero adds or modifies a cite field in word, I'd like to trigger a Word macro to do something with that field. Is this possible?


Specifically, I'm trying to create a workaround for this problem:
I want author-only cites (inverse of "suppress author"), but I'm not getting a reply or suggestions in the other thread.

(I think this can be done by supplying a page number of "0" and then recognizing that within word, and modifying the cite field accordingly. Not pretty, but I hope it works.)
  • Write a word macro to call the Zotero macro, then perform additional steps.
  • Ah, that makes sense. Is there some way to modify the Zotero toolbar or should I just make my own clone of it with my own buttons? I suppose that might be easier.

  • Making a clone of it (I out a similar one in the References tab) is better.
  • edited August 11, 2018
    Makes sense. Trying to do that now.

    But when I do that, I end up calling the Zotero function, then the Zotero menu opens, and in the background my personal macro runs, so it doesn't wait until the Zotero process is done.

    Trying to figure out the timing here, but any advice would be appreciated :)
  • I would actually need to see VBA code to comment on your macro. As far as I am aware, VBA is fully synchronous.
  • You should call the Zotero macro (e.g., ZoteroAddEditCitation), not invoke clicking a button.
  • edited August 11, 2018
    The problem seems to be that Zotero calls a shell command to perform any macro actions, so it's not actually running through VBA.*

    Here's the macro I'm trying to run after Zotero finishes updating a field:
    Application.Run MacroName:="ZoteroInsertCitation"
    fieldLoc = ActiveDocument.Range(0, Selection.End).Fields.Count ' find the ID of the last field up to the current cursor/selection
    If fieldLoc > 0 Then ' if there is a last field
    fieldText = ActiveDocument.Fields(fieldLoc).Code.Text ' get the current text of the field
    If InStr(fieldText, " ADDIN ZOTERO_ITEM CSL_CITATION") = 1 Then ' make sure this is a Zotero field to modify
    ZoteroFieldFix ActiveDocument.Fields(fieldLoc) ' change field to author-only
    End If
    End If
    End Sub

    "ZoteroFieldFix" is a separate function that actually modifies the field. That seems to work without any issues, but obviously must take place after Zotero has finished changing the field or it is pointless.

    [*I found some suggestions about alternatives to the Shell command that would be synchronous, waiting for the result, but I would rather not have to change On the other hand, it is kind of odd that you can continue editing/working on Word while Zotero is open and is going to presumably change things after you have edited something else in the document. But that's outside the scope of this discussion I suppose.]
  • Here's what I ended up with, after giving up on trying to integrate the timing better. I just don't see a way to do it, without changing Zotero's Shell function.
Sign In or Register to comment.