I'm trying to pass a queue to a function in VBA and have that function's actions not effect the queue object in the calling function. 

For example in the code below queue starts with a size of 5000. Then queue is passed to RemoveOneFromQueue and the size decreases to 4999. I want queue in Main\_Test to be unaffected by the actions in RemoveOneFromQueue. I thought using ByVal in the function parameters would accomplish this but it doesn't seem to help. Any ideas if this is possible?

I don't want to regenerate the queue each time as the real version will take too long to do that.

```
Sub Main_Test()
    Dim queue As Object
    Dim i As Long
    Set queue = GenerateQueue()
    Debug.Print queue.Count

    i = RemoveOneFromQueue(queue)
    Debug.Print queue.Count
End Sub

Function GenerateQueue() As Object
    Dim i As Long
    Dim queue As Object
    Set queue = CreateObject("System.Collections.Queue")
    For i = 1 To 5000
        queue.Enqueue i
    Next i
    Set GenerateQueue = queue
End Function

Function RemoveOneFromQueue(ByVal queue As Object) As Double
    Dim i As Long
    i = queue.Dequeue()
    RemoveOneFromQueue = i
End Function

```