ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Valid File Path Format (https://www.excelbanter.com/excel-programming/298307-valid-file-path-format.html)

Todd huttenstine

Valid File Path Format
 
Good morning

How do you check a value to see if it is in a valid file
path format?


Thank you
Todd Huttenstine

Chip Pearson

Valid File Path Format
 
Todd,

I don't think there is a (built in) way to check just the syntax
of a file name. Since, I assume, you are going to use the value
to open or save a file, just go ahead and do the operation and
use an error trap to determine the success of the operation. An
alternative would be to use the Dir() function, and test for an
error.

Dim FNum As Integer
Dim FName As String
On Error GoTo ErrH:
FName = "invalid/::???file\\\??name"
FNum = FreeFile()
If Dir(FName) = "" Then
' do nothing
End If
Exit Sub
ErrH:
If Err.Number = 52 Then
MsgBox "Invalid filename "
End If



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com





"Todd Huttenstine" wrote in
message ...
Good morning

How do you check a value to see if it is in a valid file
path format?


Thank you
Todd Huttenstine




Stephan Kassanke

Valid File Path Format
 

"Todd Huttenstine" schrieb im
Newsbeitrag ...
Good morning

How do you check a value to see if it is in a valid file
path format?


Thank you
Todd Huttenstine


Hi Todd,

no "out of the box" solution, but you should pay attention to the following
points:

- Path length is limited to 254 chars on Windows systems AFAIK
- Some characters are not allowed (?, *, etc.) so check your string for
occurences of these chars, e.g. with Instr(...)
- Does valid also mean that the path exists? If so, the following function
might be useful:

rivate Function PathExists(pname) As Boolean
' Returns TRUE if the path exists
Dim x As String
On Error Resume Next
x = GetAttr(pname) And 0
If Err = 0 Then PathExists = True _
Else PathExists = False
End Function

(taken from: http://www.j-walk.com/ss/excel/tips/tip54.htm)

Another useful link is: http://www.primeconsulting.com/faqs/faq2000.html

HTH, cheers,
Stephan



Todd huttenstine

Valid File Path Format
 
Thanks didnt think about doing that. It works. I looked
in VBA help and could not find a list of all the error
numbers. Do you have a list that lists all the possible
err types?

Todd
-----Original Message-----
Todd,

I don't think there is a (built in) way to check just the

syntax
of a file name. Since, I assume, you are going to use the

value
to open or save a file, just go ahead and do the

operation and
use an error trap to determine the success of the

operation. An
alternative would be to use the Dir() function, and test

for an
error.

Dim FNum As Integer
Dim FName As String
On Error GoTo ErrH:
FName = "invalid/::???file\\\??name"
FNum = FreeFile()
If Dir(FName) = "" Then
' do nothing
End If
Exit Sub
ErrH:
If Err.Number = 52 Then
MsgBox "Invalid filename "
End If



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com





"Todd Huttenstine"

wrote in
message ...
Good morning

How do you check a value to see if it is in a valid file
path format?


Thank you
Todd Huttenstine



.



All times are GMT +1. The time now is 12:40 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com