Checking a Directory for a new file name that contains specific text

Stabi

New Member
Joined
Jul 1, 2019
Messages
1
Hi, Long time reader, first time poster...

I have a table with with a list of values that represent serial numbers. Im looking for some VBA code that will check a specific directory to see if someone has added a file where the filename contains one of the serial numbers and updates the value in an adjacent cell (from "No" to the filename for example).

These files are being created and save to a directory over time so from time to time I would need to open this workbook and update. Could possible assign a macro to a button to run a check.

Im thinking something that uses a loop to run down the list and check each serial number and return a response the cell offset by 1 column.

Col ACol B
Serial NumberFile exists in DIRcomment
185029OPT_185029_20190622.xlsx
filename could be something like: OPT_185029_20190622.xlsx or 185029-DW.xlsx
185030No
185031No

<tbody>
</tbody>

Hopefully someone has some ideas

Thanks
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Try this

Code:
Public Sub test()
    MsgBox CheckFileExists("C:\Users\Bob\Documents\Projects\_8 Community\Forums\VBAExpress", "65382")
End Sub
Public Function CheckFileExists(ByVal Path As String, ByVal FileId As String) As Boolean
    CheckFileExists = Dir(Path & Application.PathSeparator & "*" & FileId & "*") <> vbNullString
End Function
 
Upvote 0

Forum statistics

Threads
1,214,560
Messages
6,120,217
Members
448,951
Latest member
jennlynn

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