Public Function GetArrayInfo(TheArray As Variant, ArrayInfo As SAFEARRAY) As Boolean
Dim lp As Long, VType As Integer
If Not IsArray(TheArray) Then Exit Function
With ArrayInfo
' Get the VARTYPE value from the first 2 bytes of the VARIANT structure
CopyMemory ByVal VarPtr(VType), ByVal VarPtr(TheArray), 2
' Get the pointer to the array descriptor (SAFEARRAY structure)
' NOTE: A Variant's descriptor, padding & union take up 8 bytes.
CopyMemory ByVal VarPtr(lp), ByVal (VarPtr(TheArray) + 8), 4
' Test if lp is a pointer or a pointer to a pointer.
If (VType And VT_BYREF) <> 0 Then
' Get real pointer to the array descriptor (SAFEARRAY structure)
CopyMemory ByVal VarPtr(lp), ByVal lp, 4
End If
' Fill the SAFEARRAY structure with the array info
' NOTE: The fixed part of the SAFEARRAY structure is 16 bytes.
CopyMemory ByVal VarPtr(ArrayInfo.cDims), ByVal lp, 16
' Ensure the array has been dimensioned before getting SAFEARRAYBOUND information
If ArrayInfo.cDims > 0 Then
' Size the array to fit the # of bounds
ReDim .rgsabound(1 To .cDims)
' Fill the SAFEARRAYBOUND structure with the array info
CopyMemory ByVal VarPtr(.rgsabound(1)), ByVal lp + 16,