Home |
Search |
Today's Posts |
|
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Is filepath valid?
I have a column that contains a file path with the file at the end - all
contained in the cell. There are about 150 rows. I would like to put something in column be that says - yes the path and file are truly there or No it is invalid. I have searched multiple places and have not found anything pointing to how to do this? |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Is filepath valid?
I was going to answer as Mike did, but in testing I saw something I'd never
noticed before - if you are looking at a server or shared drive on a network, referring to one that does not exist with DIR yields an error, not just an empty string, as Dir usually does. At least I think that's what I'm seeing. So here's my function: Function valid_path_and_file(path_and_file As String) As Boolean Dim tester As String On Error Resume Next tester = Dir(path_and_file, vbDirectory) If Err.Description = "" Then 'If Server5 and SHARE exist If tester < "" Then valid_path_and_file = True End If End If On Error GoTo 0 End Function I called it with this. Again if Server5 or SHARE do not exist, Dir errored in my test, but the function above did not: Sub test() Debug.Print valid_path_and_file("\\Server5\SHARE\GENERAL\test. doc") End Sub hth, Doug "Rookie_User" wrote in message ... I have a column that contains a file path with the file at the end - all contained in the cell. There are about 150 rows. I would like to put something in column be that says - yes the path and file are truly there or No it is invalid. I have searched multiple places and have not found anything pointing to how to do this? |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Is filepath valid?
I used the above but appreciate this as it will help me when I move the
information over to the shared network from my laptop. "Doug Glancy" wrote: I was going to answer as Mike did, but in testing I saw something I'd never noticed before - if you are looking at a server or shared drive on a network, referring to one that does not exist with DIR yields an error, not just an empty string, as Dir usually does. At least I think that's what I'm seeing. So here's my function: Function valid_path_and_file(path_and_file As String) As Boolean Dim tester As String On Error Resume Next tester = Dir(path_and_file, vbDirectory) If Err.Description = "" Then 'If Server5 and SHARE exist If tester < "" Then valid_path_and_file = True End If End If On Error GoTo 0 End Function I called it with this. Again if Server5 or SHARE do not exist, Dir errored in my test, but the function above did not: Sub test() Debug.Print valid_path_and_file("\\Server5\SHARE\GENERAL\test. doc") End Sub hth, Doug "Rookie_User" wrote in message ... I have a column that contains a file path with the file at the end - all contained in the cell. There are about 150 rows. I would like to put something in column be that says - yes the path and file are truly there or No it is invalid. I have searched multiple places and have not found anything pointing to how to do this? |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Is filepath valid?
This seems to work well:
Public Function bFileExists(ByVal sFile As String) As Boolean Dim lAttr As Long On Error Resume Next lAttr = GetAttr(sFile) bFileExists = (Err.Number = 0) And ((lAttr And vbDirectory) = 0) On Error GoTo 0 End Function RBS "Rookie_User" wrote in message ... I have a column that contains a file path with the file at the end - all contained in the cell. There are about 150 rows. I would like to put something in column be that says - yes the path and file are truly there or No it is invalid. I have searched multiple places and have not found anything pointing to how to do this? |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Is filepath valid? | Excel Programming | |||
Create filepath if it's not available | Excel Programming | |||
Filepath | Excel Discussion (Misc queries) | |||
Filepath | Excel Discussion (Misc queries) | |||
get filename and filepath | Excel Programming |