I am still a beginner with VB. With that stated, I am creating a vb script to help make part of my job a little easier but am havign a slight issue. I need pull all the file names from a directory (including subfolders) have them output in a column in Excel 2007. I get the first part to work GREAT, BUT my main issue is that when it outputs the list I need to replace "C:\" with "\\abcdefg123\" . I need just that part replaced with the rest of the file path following.
Sub FileNames()
ListFilesInFolder "C:\<parent folder>\<subfolder>\<file>", True
End Sub
Sub ListFilesInFolder(SourceFolderName As String, IncludeSubfolders As Boolean)
Dim FSO As Scripting.FileSystemObject
Dim SourceFolder As Scripting.Folder, SubFolder As Scripting.Folder
Dim FileItem As Scripting.File
Dim r As Long
Set FSO = New Scripting.FileSystemObject
Set SourceFolder = FSO.GetFolder(SourceFolderName)
r = Range("A65536").End(xlUp).Row + 1
For Each FileItem In SourceFolder.Files
' display file path
Cells(r, 1).Formula = FileItem.Path
r = r + 1 ' next row number
Next FileItem
If IncludeSubfolders Then
For Each SubFolder In SourceFolder.SubFolders
ListFilesInFolder SubFolder.Path, True
Next SubFolder
End If
Columns("A:Z").AutoFit
Set FileItem = Nothing
Set SourceFolder = Nothing
Set FSO = Nothing
ActiveWorkbook.Saved = True
End Sub
Bookmarks