check files exist when cell values change

kaffal

Board Regular
Joined
Mar 7, 2009
Messages
68
hi i will like to have a macro to check whether a file exist when one of the cell values are changed.

<table style="font-family: Calibri,Arial; font-size: 11pt; background-color: rgb(255, 255, 255); padding-left: 2pt; padding-right: 2pt;" border="1" cellpadding="0" cellspacing="0"> <colgroup><col style="font-weight: bold; width: 30px;"><col style="width: 66px;"><col style="width: 106px;"></colgroup><tbody><tr style="background-color: rgb(202, 202, 202); text-align: center; font-weight: bold; font-size: 8pt;"><td> </td><td>H</td><td>I</td></tr><tr style="height: 14px;"><td style="font-size: 8pt; background-color: rgb(202, 202, 202); text-align: center;">16</td><td style="font-family: Arial; font-size: 8pt;">Directory</td><td style="font-family: Arial; font-size: 8pt;">C:\today\sales</td></tr><tr style="height: 14px;"><td style="font-size: 8pt; background-color: rgb(202, 202, 202); text-align: center;">17</td><td style="font-family: Arial; font-size: 8pt;">File Name </td><td style="font-family: Arial; font-size: 8pt;">090309_sales.xls</td></tr><tr style="height: 14px;"><td style="font-size: 8pt; background-color: rgb(202, 202, 202); text-align: center;">18</td><td style="font-family: Arial; font-size: 8pt;">Files found </td><td style="font-family: Arial; font-size: 8pt;">Yes </td></tr></tbody></table>
The macro will .

- go to the path , defined from cell I16
- check whether the file name I17 is available in the path
- If exist, display "yes" is I18, if not found, display "No".

And the Macro will run everytime when the cell value in I17 are changed.

 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
How Can I amend the code to what I want?
how to create the path for the FileExists function to be used?
How to make the macro run whenever I17 cell value is changed
 
Upvote 0
I amended the function slightly:

Code:
Function FileExists(fname) As Boolean
'   Returns TRUE if the file exists
    Application.Volatile
    Dim x As String
    x = Dir(fname)
    If x <> "" Then FileExists = True _
        Else FileExists = False
End Function

Use it in your worksheet like this:

=IF(FileExists(I16&"\"&I17),"Yes","No")
 
Upvote 0

Forum statistics

Threads
1,203,397
Messages
6,055,165
Members
444,767
Latest member
bryandaniel5

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