Reputation: 29
Lets say that I have a spreadsheet in excel named test.xls and inside it a column named column1 with values image1, image2, etc. And I have a folder named images, contain images of type jpg, named like the values in the column image1.jpg, image2.jpg, etc. I need a Vba code to check if the images exist in the folder based on the spreadsheet column. Thank you!
Upvotes: 0
Views: 1651
Reputation: 814
This example will display the search results in another column. Edit the variables and don't forget the last \ in the folder path.
Sub checkFiles()
Dim count&, lastRow&
Dim folderPath, columnRead, columnWrite As String
folderPath = "C:\EXAMPLE\"
columnRead = "A"
columnResults = "B"
lastRow = ThisWorkbook.Sheets(1).Range(columnRead & Rows.count).End(xlUp).Row
For count = 1 To lastRow
Range(columnRead & count).Activate
If Dir(folderPath & Range(columnRead & ActiveCell.Row).Value) <> "" Then
Range(columnResults & ActiveCell.Row).Value = "File exists."
Else
Range(columnResults & ActiveCell.Row).Value = "File doesn't exist."
End If
Next count
End Sub
Upvotes: 2