Solved

latebinding Windows Script Host Object

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

920 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

13 Experts available now in Live!

Get 1:1 Help Now