So you have the folders in Row 1 and want the filenames under each "folder
header" starting in row 2?
Option Explicit
Sub testme()
Dim myNames() As String
Dim fCtr As Long
Dim myFile As String
Dim myPath As String
Dim myCell As Range
Dim myRng As Range
With Worksheets("sheet1")
Set myRng = .Range("a1", .Cells(1, .Columns.Count).End(xlToLeft))
For Each myCell In myRng.Cells
myPath = myCell.Value
If Right(myPath, 1) <> "\" Then
myPath = myPath & "\"
End If
myFile = ""
On Error Resume Next
myFile = Dir(myPath & "*.xls")
On Error GoTo 0
If myFile = "" Then
myCell.Offset(1, 0).Value = "No files!"
Else
'get the list of files for that folder
'clean up existing names
Erase myNames
fCtr = 0
Do While myFile <> ""
fCtr = fCtr + 1
ReDim Preserve myNames(1 To fCtr)
myNames(fCtr) = myFile
myFile = Dir()
Loop
If fCtr > 0 Then
If fCtr > (.Rows.Count - 1) Then
'it won't fit, what should happen??
MsgBox "not enough columns!"
Else
myCell.Offset(1, 0).Resize(fCtr, 1).Value _
= Application.Transpose(myNames)
End If
End If
End If
Next myCell
End With
End Sub
==========
Even though I don't use access, I would think that automating Access is better
than just starting it via a hyperlink.
But you may want to give something like this a try.
Thisworkbook.followhyperlink "file:////C:\My Documents\db1_2K.mdb"
But you may end up getting those security prompts that you get with hyperlinks.
hi dave your versions great the only downside is that it goes from column to
column where as i need it to go row to row. i tried changing the offsets and
the definition to rows but all i ended up with was nofiles in my rows???
i managed to get a version before your reply and it works great.....until i
select a diffrent drive to c: then it stops working altogether please find
code below. your version however was able to search my d: which is brilliant
oh and the help to open the db i needed was cool too i tried so many
diffrent types of code (followhyperlink, openapp etc) but that one does the
job perfectly
thanks dave any further help is definatly appreciated
rivers
Sub Open_All_Files()
Dim sFil, sPath, sel As String
Dim i As Integer
sPath = d:\ 'location of files
sel =xls
Range("B:B").ClearContents
ChDir sPath
sFil = Dir("*." & sel) 'change or add formats
i = 3
Do While sFil <> "" 'will start LOOP until all files in folder sPath have
been looped through Set oWbk = Workbooks.Open(sPath & "\" & sFil) 'opens the
file
i = i + 1
Range("b" & i) = sFil 'put filename into cell range i
sFil = Dir
Loop ' End of LOOP
End Sub