View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Jim Thomlinson Jim Thomlinson is offline
external usenet poster
 
Posts: 5,939
Default Collection::Item runtime error

Check out this link...

http://www.cpearson.com/excel/variables.htm

Set is used with objects when you want to create, modfy or destroy the
object. (You can change the properties of an existing object without set)
--
HTH...

Jim Thomlinson


"PaulH" wrote:

On Aug 27, 1:45 pm, "Jim Cone" wrote:
You need a Set statement to create the Collection...
Set FileNames_ = New Collection.

Also, the first item in a Collection has an index of 1,
while the first item in a Listbox has an index of 0.
--
Jim Cone
San Francisco, USAhttp://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)

"PaulH"
wrote in message
I have an excel vba macro that uses a collection to store some string
data. The collection 'key' is a string that is shown in a listbox. (as
below)
When accessing the 'Item' property, I get the runtime error: "Object
variable or With block variable not set"

' lbFiles is a listbox
Dim FileNames_ As Collection
Private Sub btn_Click()
Dim ListItem As Integer
ListItem = GetSelected()

If ListItem -1 Then
Dim Path As String
Path = FileNames_.item( lbFiles.List(ListItem)) 'error here
'...
End If

'...
End Sub
I noticed that in all the documentation, the 'Item' property is upper
case, but if I try to type 'FileNames_.Item' in to vba, it
automatically lowers the case. (as above) Does that make a difference?
Thanks,
Paul


Ah, the 'new' keyword does it!

What does the 'set' keyword do? Does it replace the 'Dim'?
Is there a 'delete' (or something equivalent) I need to do since I'm
using 'new'?

Thanks,
PaulH