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.

[TABLE="class: grid, width: 1000"]
<tbody>[TR]
[TD]Col A[/TD]
[TD]Col B[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Serial Number[/TD]
[TD]File exists in DIR[/TD]
[TD]comment[/TD]
[/TR]
[TR]
[TD]185029[/TD]
[TD]OPT_185029_20190622.xlsx
[/TD]
[TD]filename could be something like: OPT_185029_20190622.xlsx or 185029-DW.xlsx[/TD]
[/TR]
[TR]
[TD]185030[/TD]
[TD]No[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]185031[/TD]
[TD]No[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

Hopefully someone has some ideas

Thanks
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
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,223,889
Messages
6,175,223
Members
452,620
Latest member
dsubash

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