View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Populate Combo Box with Text file

Maybe something like:

Option Explicit
Sub auto_open()

Dim myFileName As String
Dim myLine As String
Dim testStr As String
Dim FileNum As Long

myFileName = "G:\MyText.txt"

testStr = ""
On Error Resume Next
testStr = Dir(myFileName)
On Error GoTo 0

If testStr = "" Then
Exit Sub
End If

Worksheets("sheet1").ComboBox1.Clear

FileNum = FreeFile
Close #FileNum
Open myFileName For Input As #FileNum
Do While Not EOF(FileNum)
Line Input #1, myLine
Worksheets("sheet1").ComboBox1.AddItem myLine
Loop

Close #FileNum

End Sub


Steve C wrote:

I have created a Combo box on a spreadsheet (using the Control Box Toolbar)
that I would like to populate from a text file on our network
(G:\MyText.txt). I do not wish to use a range of cells on the spreadsheet to
store the data, nor data validation. Can you help? Thanks!

Steve C


--

Dave Peterson