• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1906
  • Last Modified:

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

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
dhalliday
Asked:
dhalliday
  • 2
1 Solution
 
RobSampsonCommented:
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
 
RobSampsonCommented:
Thanks for the grade.

Regards,

Rob.
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now