John has a column of invoice numbers in a worksheet. He has a directory on the network where staff save a PDF of the actual invoice and name it using the same invoice number that is in the worksheet. Each invoice number in the worksheet should have a correspondingly named PDF in the directory on the network. John is looking for a way, within Excel, to check and verify that a PDF really does exist for each invoice number.
There is no way to do this using built-in Excel commands. You can, however, create a macro that will do the checking for you. For instance, consider the following simple user-defined function:
Function FileExists1(sPath As String) FileExists = Dir(sPath) <> "" End Function
The routine simply returns a True or False value, based on whether the specified file exists. The value that is passed to the function needs to include a full path and file name. For example, if the file specification (including the path) were in cell A1, you could use the following in a cell:
=FileExists1(A1)
You may not, however, want to put the full path name into the cell. In that case, you could specify it in the actual formula, in this way:
=FileExists1("c:\your\path\here\" & A1 & ".pdf")
Of course, you could instead specify the path in the user-defined function:
Function FileExists2(sFile As String) sPath = "c:\your\path\here\" & sFile & ".pdf" FileExists = Dir(sPath) <> "" End Function
With such a function you could easily create a formula in your worksheet that would "flag" any invoices missing from the directory:
=IF(FileExists2(A1),"","Missing Invoice")
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (7402) applies to Microsoft Excel 2007, 2010, and 2013. You can find a version of this tip for the older menu interface of Excel here: Checking for the Existence of a File.
Solve Real Business Problems Master business modeling and analysis techniques with Excel and transform data into bottom-line results. This hands-on, scenario-focused guide shows you how to use the latest Excel tools to integrate data from multiple tables. Check out Microsoft Excel 2013 Data Analysis and Business Modeling today!
Macros allow you to perform all sorts of file-related operations. One such operation allows you to delete a directory. ...
Discover MoreWhen you enter information into a workbook, Excel automatically recalculates every worksheet in every open workbook on ...
Discover MoreWant to easily control which records get imported from a text file into Excel? It's easy to do when you write the macro ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
2018-01-22 11:26:52
Fallon
First, I put the function in "This Workbook" and when I called the function I get "#NAME" error. I then tried putting the function in my Personal Macro Workbook and I still get the same error. Not sure how to implement this properly.
2018-01-18 13:32:51
Tariq
Hello,
Thank you for such great tutorial.
I have the same thing but with 10K raws, each raw has about 5 images, and sperated with comma ','
Would you please advise me how to solve this and check if the image in the folder or no?
Also, is there a way to remove the missing image from the cell?
Thank you again,
2016-08-19 11:45:57
Michael Heavener
Is there a macro that will flag files in the folders as changed or tell me when new ones are added. I can set alerts in SharePoint but it would also be nice to not hand-add them to the Excel tracker.
2016-08-18 02:29:55
SALU
ITS NOT WORKING.....
2016-08-17 08:45:32
ovi
there is any method to make excel to look in all folders contained by a specified location if the searched file exists without specifying full path. For example to check if file "file1.pdf" exists in any of the folders contained by "c:main folder" ?
2016-03-17 09:45:26
Kpax7
OK, Got it working. You should press Alt+Ctrl+Shift+F9 to force excel to calculate all formulas otherwise it still says missing invoice.
Using Office 2013
Thanks
2016-03-17 09:30:07
Kpax7
Not working, not even with GB's suggestion.
2015-03-05 10:44:39
GB
It looks like there is an error in the code.
Try:
Function FileExists1(sPath As String)
FileExists1 = Dir(sPath) <> ""
End Function
2014-08-21 05:00:15
Dear,
I won't get it working:).
Do you have a example sheet?
Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2018 Sharon Parq Associates, Inc.
Comments