LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.misc
michaelberrier
 
Posts: n/a
Default Opening files from a combo box

I use the rather verbose code below to list .xls files in a specific
folder in a combo box. How do I format the combo box and/or Userform
to allow users to open the selected file?

Thanks for the help.

Sub Start()
Dim DirToSearch As String
UserForm2.ComboBox1.Clear
DirToSearch = "C:\Manifest\Manifest Archive\" 'THE FOLDER
GetFilesInDirectory DirToSearch
'remove ' in next line to include subfolders:
'LookForDirectories (DirToSearch)
UserForm2.Show
End Sub
Sub LookForDirectories(ByVal DirToSearch As String)
Dim counter As Integer
Dim i As Integer
Dim Directories() As String
Dim Contents As String

counter = 0
DirToSearch = DirToSearch & "\"
Contents = Dir(DirToSearch, vbDirectory)
Do While Contents < ""
If Contents < "." And Contents < ".." Then
If (GetAttr(DirToSearch & Contents) And vbDirectory) =
vbDirectory Then

counter% = counter% + 1
ReDim Preserve Directories(counter)
Directories(counter) = DirToSearch & Contents
End If
End If
Contents = Dir
Loop
If counter = 0 Then Exit Sub
For i = 1 To counter
GetFilesInDirectory Directories(i)
LookForDirectories Directories(i)
Next i
End Sub
Sub GetFilesInDirectory(ByVal DirToSearch As String)
Dim NextFile As String
NextFile = Dir(DirToSearch & "\" & "*.xls")
Do Until NextFile = ""
UserForm2.ComboBox1.AddItem NextFile
NextFile = Dir()
Loop
End Sub

 
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
Issue opening csv files in Excel Emre Yigit Excel Discussion (Misc queries) 3 March 16th 06 07:24 AM
Combo box list w/ data in 2nd workbook without opening both files MHCPO Excel Worksheet Functions 0 December 15th 05 07:15 PM
disabling the Files type combo box areddy Excel Discussion (Misc queries) 1 October 19th 05 02:37 PM
Opening multiple Excel files that contain varied selected sheets MLBrownewell Excel Worksheet Functions 0 September 14th 05 05:48 PM
opening excel files with links to other data sources Saul Excel Discussion (Misc queries) 1 May 23rd 05 12:27 AM


All times are GMT +1. The time now is 05:55 PM.

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

About Us

"It's about Microsoft Excel"