Thread: dictionary keys
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Rob Bovey Rob Bovey is offline
external usenet poster
 
Posts: 811
Default dictionary keys

Hi Julio,

What you have ought to work in theory, but I get the same error you do.
It seems like the Dictionary object doesn't like late binding. If I set a
reference to the Microsoft Scripting Runtime and change the code to use
early binding as shown below it works as expected.

Sub Macro1()

Dim dic As Scripting.Dictionary
Dim s As String

Set dic = CreateObject("Scripting.Dictionary")

dic.Add "foo", "bar"

s = dic.Keys(0)

End Sub

--
Rob Bovey, MCSE, MCSD, Excel MVP
Application Professionals
http://www.appspro.com/

* Please post all replies to this newsgroup *
* I delete all unsolicited e-mail responses *


"julio" wrote in message
...
How do you access dictionary keys? What's wrong with this? (I get runtime

error "let not defined, get doesn't return object" or the other way around)

Sub Macro1()

Dim dic As Object
Dim s As String

Set dic = CreateObject("Scripting.Dictionary")

dic.Add "foo", "bar"

s = dic.keys(0)

End Sub