Macro for checking existance of a specific file on disk


Posted by Shamsuddeen. P.K on November 20, 2001 1:35 PM

I would like to have a macro which runs every time I open the workbook and it checks on the hardisk for a specific file (say c:\data\abc.xls).

If the specified file is not found in the directory, then a message box should appear on the worksheet with a message "File not found" and if the said file is found, then quit the macro and return the contol to worksheet for editing.

Posted by Russell Hauf on November 20, 2001 1:43 PM

Check the Dir function:

If Dir("c:\file") = vbNullString Then

MsgBox "File Not Found"

End If

Posted by Russell Hauf on November 20, 2001 1:46 PM

Also...

Also, to get this to run each time you open your workbook, put it in the Workbook_Open event. To do this, go to the VB editor, and double click on "This Workbook" in the Project Explorer. When you do this a new code window will appear. There should be 2 drop-downs at the top. In the left one, select WORKBOOK. This should put a function shell on the screen called "Workbook_Open". Put your code in here to run each time the workbook is opened.

Hope this helps,

Russell



Posted by Shamsuddeen. P.K on November 21, 2001 8:38 AM


Tank you very much for your response which really helped me a lot.

Regards,

Shamsuddeen