Run-time error'5' once more (2023)

edited September 6, 2023
Hi

After Zotero re-installed the word plugin this morning, I'm suddenly getting the VBA runtime error 5 as discussed previously. Worked fine last night.

Following the instructions by @adomasven here, the error can be traced to the line

wordAppPath$ = Replace(MacScript("POSIX path of (path to current application)"), " ", "%20")

When I replace this line with an innocuous MsgBox, the same error is traced to the next line with a MacScript command ("MacScript "try" & nl$ & "do shell script..").

I am surprised the MacScript command is still in there given that it is deprecated since 2021?

Zotero 6.0.27 (syncing with Zotero 7 beta on other machines)
Word 16.76.1
macOS 13.5.1

Any ideas?

Thanks
J
«1
  • I wouldn't think the VBA error would be related to the other reports, which just involved Word being closed when using any Zotero plugin function.

    Does this go away if you switch back to Zotero 6.0.26 from the download page?
  • I am on a managed machine. Will check on Friday whether I can downgrade to 26 through the software repo at work.
  • @jhimmelreich: Any follow-up on this? The 6.0.27 plugin uses a new mechanism for communicating with Word for macOS Sonoma compatibility, and some security software or policy restriction in Word on your computer is likely blocking the new method. With CrowdStrike, that resulted in a Word crash. I assume this is something else for you, and we've gotten a couple other reports of this "Run-time error '5'" error, so it would be good to know what's causing it.

    Specifically, you can tell your IT department that the 6.0.27 plugin uses curl to make an HTTP request to the Zotero app at 127.0.0.1:23119 (since Sonoma blocks the previous communication method). Hopefully they'll be able to figure out from that what on the system would be blocking that from running.
  • edited September 22, 2023
    Continued, with a Zotero.dotm file to test for pre-Sonoma systems: https://forums.zotero.org/discussion/108007/run-time-error-5-with-word-for-mac-in-zotero-6-0-27
  • didn't manage to downgrade (yet). Error seems to persist with the pre-sonoma Zotero.dotm
  • Do you also get the error if you open the posted version of the Zotero.dotm directly with Word (you may get prompted to enable Macros, and there may be two Zotero tabs, you should try both)?
  • Installed 6.0.26. Tried four combinations of app and plugin (dotm).

    ➡️ Using the .26 version of the dotm, inserting citations works both with the .26 and the .27 app version.

    ➡️ Using the .27 version of the dotm, inserting citations works with neither with the .26 and the .27 app version.

    I also tried the alternative .dotm linked to in the other discussion. Behaves like .27 dotm, i.e., error in both Zotero app versions.

    Using the .27 with the older .26 plugin generated the warning about the outdated plugin but it seemed to execute just fine.

    Hope that helps
    J
  • @dstillman and @adomasven: when I checked with the .27 and the alternative dotm, the error traces back to the line in the macro that sets wordAppPath$, we don't seem to get to the line that runs curl.
  • What is the current actual path to Word on your machine? Have you moved it from the default /Applications/Microsoft Word.app?
  • No Word is in the standard location.
  • Would you try this Zotero.dotm file and check which line you get the Run-time error on?
  • The error is in line 79 in CallZotero
    wordAppPath$ = MacScript("POSIX path of (path to current application)")
  • In case it helps, when I run the following VBA I also get an error 5
    Sub Test()
    MacScript ("beep")
    End Sub
  • And fwiw if I run the following Apple Script
    try
    do shell script "curl -s -o /dev/null -I -w '%{http_code}' -X GET http://127.0.0.1:23119/integration/macWordCommand?&agent=MacWord16&command=addCitation&document=/Application/Word.app&templateVersion=2 | grep -q '200' || exit 1"
    on error
    display alert "failed" as critical
    end try


    I get the "Zotero Integration Error" ("Zotero could not load the component necessary to communicate with your word processor. Go to Tools → Add-ons → Extensions in Zotero and make sure that the extension for your word processor is enabled")
  • The .26 version of the plugin also uses MacScript, so what you're seeing here is truly bizzare.

    Does osascript command in the terminal to run AppleScript work for you?
  • Yes, osascript -e beep for example works as intended.

    Btw: Apparently a few people here had a runtime error 5. For most the solution was to re-install the word add-in. But there seems to be at least another person here who, like me, has a persistent runtime error 5 with version .27.
  • @adomasven it is pretty strange. When I add MacScript ("beep") right in the first line after Sub CallZotero(func) I get the runtime error 5 even in Zotero .26 version of the add-in (which works otherwise). So why does the procedure not break elsewhere in the same VBA module?
  • @adomasven Actually, it's not as strange and bizarre as it seems. Using debugger breakpoints, I noticed this: In the .26 version of the add-in the MacScript call causes a runtime error, but since it is within the error handling routine On Error GoTo catch the script then jumps to catch: and the code block following this line label is executed and provides the functionality of the the add-in.

    In short, it seems that also in the .26 version of the add-in the MacScript causes a runtime error but the add-in works regardless.
  • @adomasven Now comparing the .26 add-in with the code of the add-in dotm that you linked to above (which was, I think, derivative of the .27 plugin?).

    In the .27 derivative dotm, the error handling might be part of the issue.

    One thought: The code following the catch: label in the dotm you linked to uses the MacScript procedure. That means that the code that is run in case of a runtime error includes a procedure call that likely causes the same runtime error. — As mentioned in previous post, both the .26 add-in and the .27 add-in encounter runtime error 5. The add-in of version .26 works despite the MacScript call not because of it (because the .26 error handling code provides the functionality).

    Another thought: In the dotm you linked to, there are two error handlers in the same function. I don't think I fully get how VBA handles this. Could the first one On Error GoTo customUrlNotSet interfere with the second one On Error GoTo catch? Perhaps, because the first error handler is still active, the code block following the line label catch: is never executed although (on an "intuitive" reading of the code) you'd expect it would be on a runtime error in the immediately preceding block.

    In sum, it seems to me that the main difference why the .26 add-in does work and the .27 (or the derivative version you sent) doesn't is that the .26 version uses the AppleScriptTask procedure following the catch: in case of an error.
  • Excellent debugging! Indeed the .26 version used AppleScriptTask as a fallback for people with Run-time 5 errors with MacScript, but I did not set up a similar fallback here for .27 with the changed method of communication.

    Can you place this Zotero.scpt file at ~/Library/Application Scripts/com.microsoft.Word, then try this Zotero.dotm file with Zotero 6.0.27?
  • Runtime error 5, first line that calls MacScript that is wordAppPath$ = Replace(MacScript("POSIX path of (path to current application)"), " ", "%20")

    But I am not sure I got the right Zotero.dotm. It still uses AppleScriptTask nowhere, if that was the intention; and has two error handlers and uses MacScript even in catch: block.
  • edited October 4, 2023
    Ah sorry, wrong links.

    Zotero.scpt

    Zotero.dotm
  • Runtime error 5 in line 93
    MacScript "try" & nl$ & "do shell script """ & httpShellScript$ & """" & nl$ & "on error" & nl$ & "display alert """ & onFailMessage$ & """ as critical" & nl$ & "end try"

    The error handler doesn't seem to work. This line that causes the error comes right after On Error GoTo catchMacScriptHttp. Although there is a runtime error, VBA does not jump to catchMacScriptHttp:. See my comments above about the VBA trickiness of having more than one error handler within a Sub.
  • edited October 5, 2023
    In better news, the other new code does work. That is, the following code works with Zotero .27
    Result$ = AppleScriptTask("Zotero.scpt", "callZotero", httpShellScript$)
    GoTo endSub


    Specifically, in the dotm you linked to right above, by just deleting the code block following On Error GoTo catchMacScriptHttp I got the add-in to work. The subsequent lines in Result$ = ... provided the functionality (at least for inserting citations).

    In short: Use AppleScriptTask not MacScript and don't use more than one error handler in one Sub and at least the problem that I faced should be solved.

    To get the same functionality that you want to get with the different error handlers with only one OnError you might be able to set custom error codes and use Select Case to implement the intended behavior similar to what is described here
  • Hi,

    Just a note to say I am also having this problem
    Zotero 6.0.27
    Word 16.77.1
    macOS Ventura 13.3.1 (M1 Chip)

    It seems like you are close to a solution? Would you mind posting a summary of the fix, if there is one?
  • @sam_passmore: I don't know what in that thread you're referring to. If you're talking about reverting to 6.0.26 (which is also mentioned here), that's not a fix — just a temporary workaround. You can't stay on an old version.

    We're debugging this in this thread and should have a fix soon.
  • edited October 6, 2023
    @jhimmelreich Could you try Zotero.dotm?
  • @adomasven: Same error, same line (93, first call of MacScript). Problem is still that the error handler doesn't work as it seems to be intended. It doesn't jump to catchMacScriptHttp:
Sign In or Register to comment.