Solved

latebinding Windows Script Host Object

Posted on 2010-08-13
5
259 Views
Last Modified: 2012-05-10
How do I do this please
DIm
&
Use it please?

Any example will do and I can work it out
TY
0
Comment
Question by:sirplus
  • 4
5 Comments
 
LVL 45

Expert Comment

by:patrickab
ID: 33428239
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
 
LVL 45

Accepted Solution

by:
patrickab earned 500 total points
ID: 33428275
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
 
LVL 45

Expert Comment

by:patrickab
ID: 33428858
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
 
LVL 5

Author Comment

by:sirplus
ID: 33481178
I have to use late as I dont control the environment...
0
 
LVL 45

Expert Comment

by:patrickab
ID: 33482993
sirplus - Thanks for the grade - Patrick
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question