Good morning,
I have the following code sitting behind the scenes...
Works great, except if a file is deleted from "C:\Customer_Templates".
I can add files to the folder, and column A updates, but if I delete a file, column A still displays the deleted filename.
I need it work so that if a file is deleted from "C:\Customer_Templates", it deletes the filename from the list also.
Any ideas or suggestions greatly appreciated.
N.B. Please ignore the smiley face. It should read (without spaces) / A : - D
Best regards
manc
I have the following code sitting behind the scenes...
Code:
Private Sub Workbook_Open()
Dim strFolderName As String
Dim strFileType As String
Dim pasteRange As Range
Dim returnVals As Variant
'// set parameters, change as required
strFolderName = "C:\Customer_Templates\"
strFileType = "*.xlsx"
Set pasteRange = Worksheets("Sheet1").Range("A1")
'// retrieve output of DIR command from CMD.exe
returnVals = Filter(Split(CreateObject("WScript.Shell").Exec("CMD /C DIR """ & strFolderName & _
strFileType & """ /B /A:-D").StdOut.ReadAll, vbCrLf), ".")
'// Display results in chosen column
pasteRange.Resize(UBound(returnVals) + 1, 1).Value = WorksheetFunction.Transpose(returnVals)
End Sub
Works great, except if a file is deleted from "C:\Customer_Templates".
I can add files to the folder, and column A updates, but if I delete a file, column A still displays the deleted filename.
I need it work so that if a file is deleted from "C:\Customer_Templates", it deletes the filename from the list also.
Any ideas or suggestions greatly appreciated.
N.B. Please ignore the smiley face. It should read (without spaces) / A : - D
Best regards
manc
Last edited by a moderator: