Q: Excel VBA: Extract custom class from dictionary I am having a problem with VBA Excel 2010.  I've made a custom Class called 'Enclosure', created an instance of this and added it to a dictonary.
I can then loop through the keys to ensure it has been added.
I'm having trouble then extracting my enclosure class.  Here's my code for the extraction sub:
Sub AddEnclosureItem(sItemToAdd As String, ByRef rdEnclosures As Scripting.Dictionary, dDebug As Boolean)

Dim TempEnclosure As Enclosure ' hold enclosure we pull

TempEnclosure = rdEnclosures(1)

End Sub

When I try to compile I get the 'Object Variable or With block variable not set'
Any idea's on how to proceed?  I've read somewhere you can declare a dictionary stating the items are of a certain object but I can't get it to work in 2010.  That's all I can guess at. OR a way to cast the enclosure item as it comes out.

A: When you assign an object to a variable, you have to use the Set keyword.  The opposite of Set is Let, which is used to assign a value (not an object) to a variable.  The Let keyword is optional and almost nobody uses it anymore.
The reason there's a Set and Let is because most objects have a default property - meaning that if you reference an option without a property, it will return the value stored in the default property.  The Value property is a common default property.  This
x = Range("A1")

is the same as this
x = Range("A1").Value

is the same as this
Let x = Range("A1").Value

Any is acceptable (although I prefer the second one).  That's great if x is a Double or String, but if x is a Range object variable, you need use Set
Set x = Range("A1")

If you omit the Set keyword, VBA assumes you wanted Let and tries to assign the (default) Value property to x.  That gives the 'Object variable or with block not set' error because it's trying to assign a Double or String to a Range object variable.
Your custom class module probably doesn't have a default value, so none of this should matter.  But it does.  Even if there is no default value, you have to use Set to reference the object.
