Last Update: 2023 - 05 - 24
Sudden “Invalid procedure call or argument” error in VBA
by Philipp Stiefel, originally published August 15th, 2019, last updated September 2nd, 2019
Before we start, let’s put things into perspective: “Invalid procedure call or argument” is a rather common error. If you encounter this error while writing new code, it is most likely an actual error in your code and not related to the topic of this text.
If your application’s code was running flawlessly but now suddenly fails with a Run-time error ‘5’ - “Invalid procedure call or argument”, it is probably a problem caused by the August 13, 2019 Windows updates for all current versions of Windows.
This affects all current versions of Office/VBA on Windows 10, Windows 8.1, and Windows 7 as wells as all Windows Server operating system from Windows Server 2008 through to Windows Server 2019.
Microsoft itself already added this warning to the “Known issues in this update” list.
“After installing this update, applications that were made using Visual Basic 6 (VB6), macros using Visual Basic for Applications (VBA), and scripts or apps using Visual Basic Scripting Edition (VBScript) may stop responding and you may receive an "invalid procedure call error."
Microsoft is presently investigating this issue and will provide an update when available.”
(Source: Any of the KB articles listed below)
Here is a list of the updates causing the issue (with no claim to completeness):
Some reproducible error scenarios caused by the Windows Update
I encountered two different, although related, scenarios were the “Invalid procedure call or argument” error occurs due to the installed update. Both are related to empty arrays.
Nested procedures with ParamArray arguments
If your code contains several procedures where variable ParamArray arguments are passed from one procedure to the other this will cause the error if the top level param array was empty.
Here is a small VBA code example reproducing the error.
Public Sub StartParamArrayTest() TestArray1 End Sub Private Sub TestArray1(ParamArray params() As Variant) TestArray2 params End Sub Private Sub TestArray2(ParamArray params() As Variant) TestArray3 params ' Previous line will raise error 5 - "Invalid procedure call or argument" End Sub Private Sub TestArray3(ParamArray params() As Variant) ' StubOnly, calling this will raise the error already End Sub
I haven’t found any workaround for this particular error scenario yet.
Passing an empty array ByVal
If you pass an empty array to a procedure expecting a Variant type argument ByVal, the procedure call will fail with the error message. This is probably caused by the same internal mechanics as the previous error situation.
Here is a small example reproducing the error.
Public Sub StartVarArrayTest() Dim testArray() As Object TestArrayProc testArray ' Previous line will raise error 5 - "Invalid procedure call or argument" End Sub Private Sub TestArrayProc(ByVal varArray As Variant) ' StubOnly, calling this will raise the error already End Sub
In this case the error can be prevented from appearing by passing in the empty array ByRef to the procedure.
Private Sub TestArrayProc(ByRef varArray As Variant) ' StubOnly, calling this will NOT raise the error End Sub
This should be a feasible workaround in most scenarios.
Using the Array function to clear a multi-value combo box
If you use the Array function without arguments to assign an empty array to a variable, you’ll once again see the “Invalid procedure call” error. But if you use the Array function without arguments to clear a multi-value combo box from VBA code, you will see a run-time error 2004 "There isn't enough memory to perform this operation. Close unneeded programs and try the operation again."
Private Sub Command3_Click() Me.cboMultiValue.Value = Array() End Sub
I did not encounter this variation of the issue myself but it was reported in a thread on the Access MDSN Forum.
Further considerations – “… may stop responding…”
The above-mentioned scenarios are fairly easy to diagnose, once you know about the cause of the error. However, I’m more worried about the “may stop responding” part from the description of the know issue. This is something that is much harder to track down and diagnose. Now that we know about this error, we can probably diagnose such a situation as well, but without this knowledge finding the cause would have been nearly impossible.
General Workaround / Temporary Solution
For as long as Microsoft has not released another update addressing and fixing this issue, the only real “solution” is uninstalling the August 13, 2019 Windows Updates. Once you uninstalled the update, your code will run as before. No further action necessary.
Obviously, uninstalling and deferring a security update for Windows is not ideal. You should weigh whether the effect of this update on your VBA applications is severe enough to justify this.
To my knowledge there is no know existing exploit for the security issues fixed with that update, yet. (Disclaimer: I’m not a security expert!) So, considering several applications severely affected by the problems described above, I recommended to my customers to defer the update until further notice.
Update 2019-08-18: A Fix appears to be under way …
In the late hours of August 16th Microsoft released the update August 16, 2019—KB4512494 (OS Build 16299.1365) to Windows 10, Version 1709 (only!).
The “Improvements and fixes” list for this update includes this item:
So, Microsoft seems to be really making an effort to get this mess fixed quickly. So far there is only the fix for the particular Version 1709 of Windows 10. There is no fix available for newer versions of Windows 10
Update: There is a fix available for Windows 8.1/Windows Server 2012 R2 too. This update is not listed in the update history page for Window 8.1 on the Microsoft website and it is not available via Windows Update. You can install it via the Microsoft Update Catalog. – I just installed it on my main development computer and it appears to fix all reproducible variations of this error mentioned above.
Update 2019-09-02 – Patches available for all operating systems
The week following the original, problematic Windows Update, Microsoft released a couple of patches to clean up the VBA issues. Unfortunately, the patch for the most up-to-date version of Windows 10 is was missing for some time. Finally, on August 30, Microsoft also released the path for Windows 10, V1903.
It is slightly annoying that Microsoft encourages Windows 10 users to update to the most recent version all the time, but then releases the important patch to resolve this serious VBA issue weeks later than the corresponding patches for all other operating systems.
Here is a list of all patches fixing the VBA issue:
I will never share your email with anyone. You can unsubscribe any time.
© 1999 - 2023 by Philipp Stiefel - Privacy Policiy