Checking a file path
Checking a file path
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 4 of 4

Thread: Checking a file path

  1. #1
    New Member
    Join Date
    Feb 2002
    Posts
    10
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

     
    How can I check that a file path is correct? I am getting the user to enter the path in a cell (to be used by various other macros). I then want to perform a validation on that to check that the path exists.

    Thanks

    John

  2. #2
    Board Regular Steve Hartman's Avatar
    Join Date
    Feb 2002
    Location
    Houston,Texas
    Posts
    417
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Here's a piece of code from a macro I use:

    Dim Path As String
    Path = "C:Documents and SettingsSHartmanMy DocumentsRata" & Year(Date)
    ' Check if directory for this year exists
    If Dir(Path, vbDirectory) = "" Then
    'If not, make it
    MkDir "C:Documents and SettingsSHartmanMy DocumentsRata" & Year(Date)
    End If

    Of course the double slashes should be single slashes.Hope this gets you started

    [ This Message was edited by: Steve Hartman on 2002-02-28 05:10 ]

    [ This Message was edited by: Steve Hartman on 2002-02-28 05:39 ]

    [ This Message was edited by: Steve Hartman on 2002-02-28 05:41 ]

  3. #3
    New Member
    Join Date
    Feb 2002
    Posts
    7
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    I use this function that works very well:

    If PathExists(cell) = False Then
    MsgBox cell & " does not exist.", vbOKOnly, "File Path Error."

    End If


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

  4. #4
    New Member
    Join Date
    Feb 2002
    Posts
    10
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

      
    Thanks Guys

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

 

 
DMCA.com