Solved

Using vbscript to read from an excel file and populate a drop down list

Posted on 2008-10-09
2
1,715 Views
Last Modified: 2008-10-12
I have an excel file that contains a list of names in one row and the distinguished name in another.


I need to read the file and output the names into the drop down box while having the distinguished name be the value for the selection.

The following was my attempt, but was unsuccessful.

strXLpath = "c:\managers.xls"
      
            Set objXL = CreateObject("Excel.Application")
            objXL.visible = False
            Set objWb = objXL.WorkBooks.Open(strXLpath)
            

            objWb.MoveFirst
            Do Until objWb.EOF
                  Set objOption = Document.createElement("OPTION")
                        objOption.Text = objXL.Rows(1).Value
                        objOption.Value = objXL.Rows(2).Value
                        mgrName.Add(objOption)
                        objWB.MoveNext
            Loop


0
Comment
Question by:dhalliday
  • 2
2 Comments
 
LVL 65

Accepted Solution

by:
RobSampson earned 500 total points
ID: 22682399
Hi, assuming you've got Manager name in column A and their distriguished name in Column B, try this....

Regards,

Rob.
strXLpath = "c:\managers.xls"
 
Set objXL = CreateObject("Excel.Application")
Const xlUp = -4162
objXL.visible = False
Set objWb = objXL.WorkBooks.Open(strXLpath)
Set objSheet = objWb.Sheets(1)
 
For intRow = 2 To objSheet.Cells(65536, "A").End(xlUp).Row
	Set objOption = Document.createElement("OPTION")
	objOption.Text = objSheet.Cells(intRow, "A").Value
	objOption.Value = objSheet.Cells(intRow, "B").Value
	mgrName.Add(objOption)
Next

Open in new window

0
 
LVL 65

Expert Comment

by:RobSampson
ID: 22699075
Thanks for the grade.

Regards,

Rob.
0

Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Welcome back!  My apologies for taking so long to write part two of this series; it's been a long time coming!  As I promised in Part 1, this article will focus on how to locate those elusive AD properties that you are searching for.  Why is this us…
Introduction During my participation as a VBScript contributor at Experts Exchange, one of the most common questions I come across is this: "I have a script that runs against only one computer. How can I make it run against a list of computers in …
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

823 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