Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 301
  • Last Modified:

latebinding Windows Script Host Object

How do I do this please
DIm
&
Use it please?

Any example will do and I can work it out
TY
0
sir plus
Asked:
sir plus
  • 4
1 Solution
 
patrickabCommented:
sirplus,

As code below and the rather poor example file attached.

Patrick
Sub tester()
Dim dic As Object
Dim rng As Range
Dim cel As Range

Set dic = CreateObject("Scripting.Dictionary")

dic.Add "message1", "msg1"
dic.Add "message2", "msg2"

Set rng = Range("a5:a7")
Range("a5") = "garbage"
Range("a6") = "message1"
Range("a7") = "message2"

For Each cel In rng.Cells
    If dic.Exists(cel.Value) Then
        Application.Run dic(cel.Value)
    Else
        MsgBox dic.Item(cel.Value) & " not defined"
    End If
Next

Set dic = Nothing

End Sub

Open in new window

dictionary-example-03.xls
0
 
patrickabCommented:
BTW - I use Excel 2002 and I constantly have problems with Late Binding of the "Scripting.Dictionary" as for some reason it doesn't recognise it. I have just yesterday adopted early binding by using this construct:

Dim dic As Dictionary

'Next line needs "Microsoft Scripting Runtime" reference added
Set dic = New Dictionary
dic.CompareMode = vbTextCompare

Please note the comment about the VBA reference that you must select for this to work - Tools/References/"Microsoft Scripting Runtime"
0
 
patrickabCommented:
ps. One of the advantages of using Early Binding is that intellisense works with the Dictionary objects in the VB Editor but it doesn't with Late Binding.
0
 
sir plusSales ManagementAuthor Commented:
I have to use late as I dont control the environment...
0
 
patrickabCommented:
sirplus - Thanks for the grade - Patrick
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now