Solved

latebinding Windows Script Host Object

Posted on 2010-08-13
5
273 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Adding a text string to a formula result in Excel 7 26
Compare Excel Spreadsheet. 4 32
find a word in a cell 3 39
Input box prompt with only 5 possible entries 5 38
Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
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…

680 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