Solved

latebinding Windows Script Host Object

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

INDEX and MATCH can be used to great effect to replace HLOOKUP and VLOOKUP as it does not have the limitation of needing the data to be sorted so that the reference value is in the first column or row. It also has the ability to perform a bi-directi…
Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
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 …
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

706 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now