darkhangelsk
New Member
- Joined
- Feb 10, 2013
- Messages
- 27
Hello,
I would like to ask if there's a way for VBA to list all files (including folders) with word OLDIES_(whatever the text or number here)
Similar to this but with additional column to put location and extension.
Column will be like this (comma will be next tab):
Name, Location, extension (if folder then just folder)
OLDIES_12345, C:Desktop, Folder
OLDER_23456, C:Desktop, .zip
OLDER_23457, C:Desktop, .xls
Thank you!
I would like to ask if there's a way for VBA to list all files (including folders) with word OLDIES_(whatever the text or number here)
Similar to this but with additional column to put location and extension.
VBA Code:
Sub Example4()
Dim varDirectory As Variant
Dim flag As Boolean
Dim i As Integer
Dim strDirectory As String
strDirectory = "C:\Desktop"
i = 1
flag = True
varDirectory = Dir(strDirectory, vbDirectory)
While flag = True
If varDirectory = "" Then
flag = False
Else
Cells(i + 1, 1) = varDirectory
Cells(i + 1, 2) = strDirectory + varDirectory
'returns the next file or directory in the path
varDirectory = Dir
i = i + 1
End If
Wend
End Sub
Column will be like this (comma will be next tab):
Name, Location, extension (if folder then just folder)
OLDIES_12345, C:Desktop, Folder
OLDER_23456, C:Desktop, .zip
OLDER_23457, C:Desktop, .xls
Thank you!