#If VBA7 Then
Private Declare PtrSafe Sub memcpy Lib "kernel32" Alias "RtlMoveMemory" (ByRef dest As Any, ByVal src As LongPtr, ByVal Size As LongPtr)
#Else
Private Declare Sub memcpy Lib "kernel32.dll" (ByRef dest As Any, ByRef src As Any, ByVal Size As Long)
#End If
Public Function GetDimensions(source As Variant) As Integer
' Nota
' VT_ARRAY = &H2000 ' Tableau 1 Dimension
' VT_BYREF = &H4000 ' Tableau 2 Dimensions et 3D, 4D , et Plus...
Dim vt As Long, ptr As LongPtr
memcpy vt, VarPtr(source), 2 ' read the variant type (2 bytes) '
If (vt And &H2000) = 0 Then Exit Function ' return 0 if not an array '
memcpy ptr, VarPtr(source) + 8, Len(ptr) ' read the variant data at offset 8 '
If (vt And &H4000) Then memcpy ptr, ptr, Len(ptr) ' read by reference if the data is a reference '
If ptr Then memcpy GetDimensions, ptr, 2 ' read the number of dimensions at offset 0 (2 bytes) '
End Function