MisterProzilla
Active Member
- Joined
- Nov 12, 2015
- Messages
- 264
Hi there,
This is driving me nuts! In my current workbook I have a number of references to another workbook. In the Autpen sub, I want to check that the filepath for that external doc is still valid, and return an info message if not so the user can update the links if necessary. As I understand, I should be able to use the Dir function to look for the filepath - if it finds the file, the value returned will be non-blank, if it can't find a match, the value will be blank.
I've tried this code:
But it always returns a blank. I've tried every permutation I can think of: with and without square brackets around the filename; writing it manually into VBA rather than getting it from a cell value; tried nesting the Dir into a Len() function to check the string length instead; I've tried the Workbook.Open function using the same filename, both from a cell and written manually, and it works absolutely fine both ways. So it seems the filepath is valid - I don't understand what's going wrong with the Dir function.
Hope someone can help
This is driving me nuts! In my current workbook I have a number of references to another workbook. In the Autpen sub, I want to check that the filepath for that external doc is still valid, and return an info message if not so the user can update the links if necessary. As I understand, I should be able to use the Dir function to look for the filepath - if it finds the file, the value returned will be non-blank, if it can't find a match, the value will be blank.
I've tried this code:
Code:
'set filepath as last known location in cell D54
Dim filepath as string
filepath = Sheet3.Range("D54").Value
If Dir(filepath) = "" Then
MsgBox "File not found - check references"
Exit Sub
End If
But it always returns a blank. I've tried every permutation I can think of: with and without square brackets around the filename; writing it manually into VBA rather than getting it from a cell value; tried nesting the Dir into a Len() function to check the string length instead; I've tried the Workbook.Open function using the same filename, both from a cell and written manually, and it works absolutely fine both ways. So it seems the filepath is valid - I don't understand what's going wrong with the Dir function.
Hope someone can help
Last edited: