Brook70458
New Member
- Joined
- May 25, 2011
- Messages
- 32
I have been using this macro for several years and it has proven a great timesaver. I have tried modifying it to add the file datestamp (created and modified) to no avail; and it would be greatly beneficial to add type and size.
[ALSO, as a reference, what is a good book for data minig using MSExcel?]
Thank you in advance
Private Type BROWSEINFO ' used by the function GetFolderName
hOwner As Long
pidlRoot As Long
pszDisplayName As String
lpszTitle As String
ulFlags As Long
lpfn As Long
lParam As Long
iImage As Long
End Type
Private Declare Function SHGetPathFromIDList Lib "shell32.dll" _
Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long
Private Declare Function SHBrowseForFolder Lib "shell32.dll" _
Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As Long
Sub GetFileNames()
Dim lRow As Long
Dim sPath As String
Dim sFname As String
sPath = GetFolderName("Select a folder")
If sPath = "" Then
Exit Sub
End If
sPath = sPath & "/"
lRow = 1
Cells(lRow, "a").Value = sPath
sFname = Dir(sPath & "*.*", vbNormal)
Do Until sFname = vbNullString
lRow = lRow + 1
Cells(lRow, "a").Value = sFname
sFname = Dir
Loop
End Sub
Function GetFolderName(Msg As String) As String
' returns the name of the folder selected by the user
Dim bInfo As BROWSEINFO, path As String, r As Long
Dim X As Long, pos As Integer
bInfo.pidlRoot = 0& ' Root folder = Desktop
If IsMissing(Msg) Then
bInfo.lpszTitle = "Select a folder."
' the dialog title
Else
bInfo.lpszTitle = Msg ' the dialog title
End If
bInfo.ulFlags = &H1 ' Type of directory to return
X = SHBrowseForFolder(bInfo) ' display the dialog
' Parse the result
path = Space$(512)
r = SHGetPathFromIDList(ByVal X, ByVal path)
If r Then
pos = InStr(path, Chr(0))
GetFolderName = Left(path, pos - 1)
Else
GetFolderName = ""
End If
End Function
[ALSO, as a reference, what is a good book for data minig using MSExcel?]
Thank you in advance
Private Type BROWSEINFO ' used by the function GetFolderName
hOwner As Long
pidlRoot As Long
pszDisplayName As String
lpszTitle As String
ulFlags As Long
lpfn As Long
lParam As Long
iImage As Long
End Type
Private Declare Function SHGetPathFromIDList Lib "shell32.dll" _
Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long
Private Declare Function SHBrowseForFolder Lib "shell32.dll" _
Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As Long
Sub GetFileNames()
Dim lRow As Long
Dim sPath As String
Dim sFname As String
sPath = GetFolderName("Select a folder")
If sPath = "" Then
Exit Sub
End If
sPath = sPath & "/"
lRow = 1
Cells(lRow, "a").Value = sPath
sFname = Dir(sPath & "*.*", vbNormal)
Do Until sFname = vbNullString
lRow = lRow + 1
Cells(lRow, "a").Value = sFname
sFname = Dir
Loop
End Sub
Function GetFolderName(Msg As String) As String
' returns the name of the folder selected by the user
Dim bInfo As BROWSEINFO, path As String, r As Long
Dim X As Long, pos As Integer
bInfo.pidlRoot = 0& ' Root folder = Desktop
If IsMissing(Msg) Then
bInfo.lpszTitle = "Select a folder."
' the dialog title
Else
bInfo.lpszTitle = Msg ' the dialog title
End If
bInfo.ulFlags = &H1 ' Type of directory to return
X = SHBrowseForFolder(bInfo) ' display the dialog
' Parse the result
path = Space$(512)
r = SHGetPathFromIDList(ByVal X, ByVal path)
If r Then
pos = InStr(path, Chr(0))
GetFolderName = Left(path, pos - 1)
Else
GetFolderName = ""
End If
End Function