Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 119
Default Populate Combo Box with Text file

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
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
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 119
Default Populate Combo Box with Text file

Thanks, Dave! I'll give it a try!

"Dave Peterson" wrote:

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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to importing a text file to populate a database/table TKM New Users to Excel 1 December 14th 06 06:39 PM
populate combo box enyaw Excel Discussion (Misc queries) 1 October 26th 06 03:13 PM
Populate a combo box damorrison Excel Discussion (Misc queries) 11 September 3rd 06 09:04 PM
Populate a Combo or List Box Jonathan Excel Programming 8 September 19th 05 04:08 PM
Populate a combo Box case54321 Excel Worksheet Functions 1 June 14th 05 02:53 PM


All times are GMT +1. The time now is 02:19 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"