Search for file names that are not in a specific folder provided that their name is in a column

sofas

Well-known Member
Joined
Sep 11, 2022
Messages
559
Office Version
  1. 2021
  2. 2019
Platform
  1. Windows
Welcome. I enter the report names in column f starting from row 7 and save
Each report has a pdf file in the test folder. What I'm looking for is a code that searches inside the folder and compares the names in the f column in order to get an alert message about the names of the files entered in the column that are not inside the folder.

I found this code, but I really don't know how to modify it


VBA Code:
Sub ScanForm4()
Dim FSO As Object
Dim tTable As String, I As Long, mCnt As Long
Dim myPath As String, myF As String, myMsg As String
'
myPath = ThisWorkbook.Path & "\test"
'
With ActiveSheet
For I = 7 To .Cells(Rows.Count, "f").End(xlUp).Row
myF = Dir(myPath & .Cells(I, "f").Value & ".pdf")
If myF = "" Then
myMsg = myMsg & .Cells(I, "f") & vbCrLf
mCnt = mCnt + 1
End If
Next I
End With
If mCnt > 0 Then
myMsg = "The following files have not yet been scanned: " & vbCrLf & myMsg & vbCrLf _
& "Please scan them into the correct folder and recheck"
Else
myMsg = "Check completed, ok"
End If
MsgBox (myMsg)
End Sub
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Change this line so that it ends with a back slash, as shown:
VBA Code:
myPath = ThisWorkbook.Path & "\test\"
and your code should work, providing the PDF files are in the "test" subfolder of the workbook folder.
 
Upvote 0
Solution
Change this line so that it ends with a back slash, as shown:
VBA Code:
myPath = ThisWorkbook.Path & "\test\"
and your code should work, providing the PDF files are in the "test" subfolder of the workbook folder.
myPath = Application.ActiveWorkbook.Path & "\test\"
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,279
Members
452,630
Latest member
OdubiYouth

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top