Select option in a drop-down menu from excel file?

Posted on 2003-03-04
Medium Priority
Last Modified: 2010-04-07
I'm making a database (if you can call it that) the saves the user input into an excel file but I'm trying to load it back into the form.  Does anyone know how to do this with a drop down menu?  I've gotten desperate and resorted to using radio buttons...  
I hope it's easy and I just don't get it.
Question by:lemonduck
LVL 11

Expert Comment

ID: 8068125
when you say save into an Excel file I belive you mean a simple text file with one line of code.  So use code something similar to that. (refer to the second function)

Private Sub SaveDataToExcel()
    Dim strExcelFile As String
    Dim ArrayList(10) As String ' temporary sample array to save
    Dim i As Long
    strExcelFile = "C:\data.xls"
    ' populate array with dummy data
    For i = 0 To 10
        ArrayList(i) = Str(i)
    Next i
    Open strExcelFile For Output As #1
    'now save the array
    For i = 0 To 10
        Write #1, ArrayList(i)
    Next i

    Close #1
End Sub

Private Sub LoadDataToCombo()
    On Error GoTo LoadErr
    Dim strExcelFile As String
    Dim strComboItem As String
    Dim i As Long
    strExcelFile = "C:\data.xls"
    Open strExcelFile For Input As #1
    'now save the array
    While (Not EOF(1))  ' lopp until the end of the file
        Input #1, strComboItem  ' get each line (combo item)
        If (Trim(strComboItem) <> "") Then  ' if there is data
            combo1.AddItem strComboItem
        End If

    Close #1
    Exit Sub
    MsgBox "Error loading Data to the list" & vbcrl & Err.Number & ": " & Err.Description
    On Error GoTo 0
End Sub

Hope this is useful.  Good Luck!
LVL 49

Expert Comment

ID: 9046854
Hi lemonduck,
It appears that you have forgotten to close this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Save as PAQ -- No Refund.

lemonduck, Please DO NOT accept THIS comment as an answer.
EXPERTS: Post a comment if you are certain that an expert deserves credit.  Explain why.
DanRollins -- EE database cleanup volunteer

Accepted Solution

YensidMod earned 0 total points
ID: 9151041
Question is PAQ'd and no points refunded.

Community Support Moderator @Experts Exchange

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month8 days, 7 hours left to enroll

616 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