Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Terp
 
Posts: n/a
Default Can I import a folder's contents as a dropdown list?

I would like Excel to find the folder/file names in a folder on my hard drive
& use them as items in a dropdown list, i.e., the base folder's address might
be C:\artists. The artists folder has subfolders named "Doobie Bros", "Steely
Dan", etc. The dropdown list would show:
Doobie Bros
Steely Dan
etc.
as selectable items. I'd also like these items to be hyperlinks but that'd
just be icing on the cake, the initial list generation is the main goal.
  #2   Report Post  
John Michl
 
Posts: n/a
Default

This should get you started. I have a sheet that includes the
following ranges:
"Path" - a single cell where I type in the path to the files
"FileSpec" - a single cell where I type in the qualifier such as
"*.xls"
"FileList" - a dynamic range where the list of file names is placed.

The macro creates a list of the files in the folder and then creates
hyperlinks to each of them. Not exactly what you are looking for but a
start.

- John Michl
www.JohnMichl.com

==================================================
Sub ListFiles()

Dim p As String ' path
Dim s As String ' specifier
Dim r As Integer ' row number
Dim i As Integer 'index number
Dim l As Integer ' length of path


p = ActiveSheet.Range("Path").Value
s = ActiveSheet.Range("FileSpec").Value
r = 8
l = Len(p) + 2

' Clear previous file list if any - cell A8 is top of list
If ActiveSheet.Range("A8") < "" Then
ActiveSheet.Range("FileList").Clear
ActiveSheet.Range("FileList").Hyperlinks.Delete
End If

With Application.FileSearch
.NewSearch
.LookIn = p
.Filename = s

If .Execute() 0 Then
For i = 1 To .FoundFiles.Count
ActiveSheet.Cells(r, 1).Value = Mid(.FoundFiles(i),
l, 100)
r = r + 1
Next i

For Each cell In ActiveSheet.Range("FileList")
cell.Select
ActiveSheet.Hyperlinks.Add Anchor:=Selection,
Address:=p & "\" & cell.Value _
, TextToDisplay:=cell.Value
Next cell
Else
MsgBox "There were no files found matching the criteria."

End If
End With
End Sub

  #3   Report Post  
Terp
 
Posts: n/a
Default

Thanks, John.

I guess I should have asked if ther was an EASY way. It just seems like a
fairly common need; I guess I expected the answer to be a bit simpler. Not
being Macro savvy, I'm in the dark as far as understanding your solution goes.

I wonder if the "DIR" command could be used with the (filename) modifier to
get the names into a text file? It might be simpler to import the filenames
that way. What do you think?

Terp

"John Michl" wrote:

This should get you started. I have a sheet that includes the
following ranges:
"Path" - a single cell where I type in the path to the files
"FileSpec" - a single cell where I type in the qualifier such as
"*.xls"
"FileList" - a dynamic range where the list of file names is placed.

The macro creates a list of the files in the folder and then creates
hyperlinks to each of them. Not exactly what you are looking for but a
start.

- John Michl
www.JohnMichl.com

==================================================
Sub ListFiles()

Dim p As String ' path
Dim s As String ' specifier
Dim r As Integer ' row number
Dim i As Integer 'index number
Dim l As Integer ' length of path


p = ActiveSheet.Range("Path").Value
s = ActiveSheet.Range("FileSpec").Value
r = 8
l = Len(p) + 2

' Clear previous file list if any - cell A8 is top of list
If ActiveSheet.Range("A8") < "" Then
ActiveSheet.Range("FileList").Clear
ActiveSheet.Range("FileList").Hyperlinks.Delete
End If

With Application.FileSearch
.NewSearch
.LookIn = p
.Filename = s

If .Execute() 0 Then
For i = 1 To .FoundFiles.Count
ActiveSheet.Cells(r, 1).Value = Mid(.FoundFiles(i),
l, 100)
r = r + 1
Next i

For Each cell In ActiveSheet.Range("FileList")
cell.Select
ActiveSheet.Hyperlinks.Add Anchor:=Selection,
Address:=p & "\" & cell.Value _
, TextToDisplay:=cell.Value
Next cell
Else
MsgBox "There were no files found matching the criteria."

End If
End With
End Sub


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
import data with macro chris_rip Excel Discussion (Misc queries) 0 July 18th 05 08:40 PM
import data using macro chris_rip Excel Discussion (Misc queries) 0 July 18th 05 08:32 PM
delete all the contents (sub folders and files) in the temp folder Joseph Excel Discussion (Misc queries) 0 June 6th 05 08:01 AM
Can I use the contents of a cell to satisfy the result_vector arg. robh_2 Excel Worksheet Functions 3 February 24th 05 08:14 PM
Automatic Data Import TxRaistlin Excel Discussion (Misc queries) 2 February 4th 05 10:43 PM


All times are GMT +1. The time now is 07:27 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"