View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
smartin smartin is offline
external usenet poster
 
Posts: 915
Default Pass Object from UserForm to Code Module

Budget Programmer wrote:
Hello,

At a certain point in my code module, I need my user to determine which of
the worksheets in the workbook need further processing. In order to
accomplish this I made a UserForm with a ListBox. It lists all the
worksheets in the workbook. The user pics the worksheets that need further
processing, which I store that in a Collection. That part seems works fine.

My problem is that I can't seem to pass the collection back to the module.
I can pass a variant OK, but I can't seem to pass a collection.

What's a good way to approach this?

Many Thanks.


You can pass a collection as a parameter. E.g., this works:

'Worksheet code:
Private Sub CommandButton1_Click()
Dim myCol As New Collection
myCol.Add ("a")
myCol.Add ("c")
test myCol
End Sub

'Module code:
Sub test(acol As Collection)
Dim i As Long
For i = 1 To acol.Count
Debug.Print acol.Item(i)
Next i
End Sub

The questions for you are
- where are you building the collection
- from where are you passing the collection
- what is the scope of the collection object