ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   listing directory files in a spreedsheet automatically (https://www.excelbanter.com/excel-programming/346275-listing-directory-files-spreedsheet-automatically.html)

ALEX

listing directory files in a spreedsheet automatically
 
I have a file on my c drive that contain a lot of documents i need to find a
way to have these files listed in a colum on a spread sheet everytime a file
gets drop into a parent file automatically how can i accomplish this

chijanzen

listing directory files in a spreedsheet automatically
 
alex:

try it,

Public Sub ListFilesToWorksheet()
On Error Resume Next
Dim stMedd As String
stMedd = "Please Select Folder:"
Set obMapp = CreateObject("Shell.Application").BrowseForFolder( 0,
stMedd, &H1)
If Not obMapp Is Nothing Then
Directory = obMapp.self.Path & "\"
Else
Exit Sub
End If
With Application.FileSearch
.NewSearch
.LookIn = Directory
.Filename = "*.xls"
.SearchSubFolders = True
.Execute
For i = 1 To .FoundFiles.Count
strFileName = Dir(.FoundFiles(i))
strPath = Left(.FoundFiles(i), Len(.FoundFiles(i)) -
Len(strFileName))
strExtension = ""
Cells(i, 1) = .FoundFiles(i)
ActiveSheet.Hyperlinks.Add anchor:=Cells(i, 1),
Address:=.FoundFiles(i)
r = r + 1
Next i
End With

End Sub

--
天行健,君*以自強不息
地勢坤,君*以厚德載物

http://www.vba.com.tw/plog/


"alex" wrote:

I have a file on my c drive that contain a lot of documents i need to find a
way to have these files listed in a colum on a spread sheet everytime a file
gets drop into a parent file automatically how can i accomplish this


ALEX

listing directory files in a spreedsheet automatically
 
Hi Chijanzen had a complie error or maybe i did something wrong

"chijanzen" wrote:

alex:

try it,

Public Sub ListFilesToWorksheet()
On Error Resume Next
Dim stMedd As String
stMedd = "Please Select Folder:"
Set obMapp = CreateObject("Shell.Application").BrowseForFolder( 0,
stMedd, &H1)
If Not obMapp Is Nothing Then
Directory = obMapp.self.Path & "\"
Else
Exit Sub
End If
With Application.FileSearch
.NewSearch
.LookIn = Directory
.Filename = "*.xls"
.SearchSubFolders = True
.Execute
For i = 1 To .FoundFiles.Count
strFileName = Dir(.FoundFiles(i))
strPath = Left(.FoundFiles(i), Len(.FoundFiles(i)) -
Len(strFileName))
strExtension = ""
Cells(i, 1) = .FoundFiles(i)
ActiveSheet.Hyperlinks.Add anchor:=Cells(i, 1),
Address:=.FoundFiles(i)
r = r + 1
Next i
End With

End Sub

--
天行健,君*以自強不息
地勢坤,君*以厚德載物

http://www.vba.com.tw/plog/


"alex" wrote:

I have a file on my c drive that contain a lot of documents i need to find a
way to have these files listed in a colum on a spread sheet everytime a file
gets drop into a parent file automatically how can i accomplish this



All times are GMT +1. The time now is 03:54 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com