'// Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Private Declare PtrSafe Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDest As Any, pSource As Any, ByVal cbLength As Long)
Public Function JoinBytesArray(ParamArray ByteArrays() As Variant) As Byte()
Dim sizeArray As Variant, startIndex As Long, i As Integer
Dim Buffer() As Byte, ByteArray() As Byte
ReDim sizeArray(0 To UBound(ByteArrays))
For i = 0 To UBound(ByteArrays)
sizeArray(i) = UBound(ByteArrays(i))
Next
startIndex = 0
ReDim Buffer(WorksheetFunction.Sum(sizeArray) + UBound(sizeArray))
For i = 0 To UBound(ByteArrays)
ByteArray = ByteArrays(i)
CopyMemory Buffer(startIndex), ByteArray(0), UBound(ByteArray) + 1
startIndex = startIndex + UBound(ByteArray) + 1
Next
JoinBytesArray = Buffer
End Function
Private Function Sum(ByVal IntegerArray As Variant) As Long
Dim i As Integer
For i = 0 To UBound(IntegerArray)
Sum = Sum + Val(IntegerArray(i))
Next
'// Range.Application.WorksheetFunction.Sum
End Function