Question

I am creating an HTA file using VBScript that creates, writes to and reads from an Excel File. Basically the Excel file will be a database of "Website Names, Logins, and Passwords" (Eventually Encrypted) and the HTA just provides an Interface to view that information easily within Textboxes.

I want to create a "Drop Down Box" that is pre-populated with all the accounts currently stored in the Excel File. That way when the user selects the account name, the corresponding login and password will be displayed.

Typical code for a Drop Down Box:

<select size="1" name="DropDownBox" onChange="ReadDropdown">
    <option value="0"></option>
    <option value="1">Account 1</option>
    <option value="2">Account 2</option>
    <option value="3">Account 3</option>
</select>

Instead of Viewing "Account 1...2...3 etc" I would like the program to read the "Website Names" currently stored in the Excel File and use those names in the Dropdown box instead.

Example:

<select size="1" name="DropDownBox" onChange="ReadDropdown">
    <option value="0"></option>
    <option value="1">Facebook</option>
    <option value="2">GMAIL</option>
    <option value="3">Stack Over Flow</option>
</select>

I cant specify the names ahead of time since I have no idea what accounts will be contained in the Excel file. I assume I can modify the "Value" of the Drop Down Box options, but that wont change the text that the user actually sees (as it would in a Textbox for example).


I Did come up with an "Interesting" Idea. What if I created a Second HTA file to act as a "Loader". The Loader HTA program would do the following:

  • Open the Excel Program to see what Website Accounts are currently in the file
  • Open the Main HTA file and Edit it with the Account names found in the Excel file then SAVE it.
  • Then Run the newly Saved Main HTA file
  • And Close itself (The Loader HTA)

Just an Idea.

Était-ce utile?

La solution 2

Thank You BOTH for your responses.

@ilo I had a problem getting your answer to work, but finally figured it out. I had to make a few changes to your code in Step 2. Here is the final Working result:

MyDropDownBox.InnerHTML = "<select size='1' name='DropDownBox' onChange='ReadDropdown'> <option value="0"></option> 
<option value=" & 1 & ">" & Var1 & "</option> 
<option value=" & 2 & ">" & var2 & "</option> 
<option value=" & 3 & ">" & Var3 & "</option>
</select>" 
End Sub

** ilo's Steps 1 and 3 are still needed as well.

I ended up modifying it to suit my own code once I figured it out, but I left it like this on here to serve as a generic example for anyone else who might find this helpful.

@ilo - I was going to mark YOUR response as the Answer, but since i needed to make the small changes of using the "&" symbol when adding the values and variables, I figured I would re-write it myself. However I Give YOU Full Credit for the Answer, so Thank You.

Autres conseils

3 Steps.

  1. Create empty span and assign it ID in the place you want to see your dropdown box

    <span id=MyDropdownBox> <span>

  2. Create a Sub to read the values from Excel and fill your empty span with HTML code. The HTML part of code should be within the quote marks and variables are not. And I guess you will have to fit it in one line for more reliability!

    Sub DisplayDropdownBox() '// Your code to get the values from Excel and assign to variables. '// Then fill the empty span with dropdown list with values you got. MyDropDownBox.InnerHTML = "<select size='1' name='DropDownBox' onChange='ReadDropdown'> <option value="0"></option> <option value="1">"Var1"</option> <option value="2">"var2"</option> <option value="3">"Var3"</option> </select>" End Sub

  3. Put this kind of code to the beginning of your VBscript, this will be called each time you run or refresh the hta window Sub Window_onLoad DisplayDropdownBox() End Sub

PS: I had hard time formatting this text, so if anyone want to improve the formatting, can try to do so. Also you can check out my answer in raw text file myanswer.txt

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top