Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending object array to variant works before August 2019 Windows update, but fails after update

Tags:

excel

vba

Running the subroutine RunMe works before August 2019 Windows update.

Running the subroutine RunMe fails after August 2019 Windows update. It reports the following error message: "Invalid procedure call or argument (Error 5)"

Public Sub RunMe()
  Dim wksTestArray() As Worksheet
  MsgBox SendArrayToFunction(wksTestArray())
End Sub

Public Function SendArrayToFunction(ByVal vntArray As Variant) As Boolean
  SendArrayToFunction = True
End Function

Please note: The error only occurs for an unallocated array.

It can be useful for a function to accept a Variant, which can be either an Array of values, or an Array of objects, for example, IsArrayAllocated is an example function where this would be required.

Is there a fix?

like image 415
M1chael Avatar asked Aug 14 '19 15:08

M1chael


2 Answers

The update affects VB6, VBA (including all versions of Office) as well as VBScript!

Microsoft is currently looking into the issue: https://support.microsoft.com/en-us/help/4512488/windows-8-1-update-kb4512488 (look at the last row under the section entitled "Known issues in this update")

Update:

Microsoft just released a patch for this issue: https://support.microsoft.com/en-us/help/4517298/windows-8-1-update-kb4517298

like image 82
vbguyny Avatar answered Oct 06 '22 23:10

vbguyny


To fix, change the ByVal to ByRef in the function:

Public Sub RunMe()
  Dim wksTestArray() As Worksheet
  MsgBox SendArrayToFunction(wksTestArray())
End Sub

Public Function SendArrayToFunction(ByRef vntArray As Variant) As Boolean
  SendArrayToFunction = True
End Function
like image 28
M1chael Avatar answered Oct 06 '22 22:10

M1chael