1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Solved: dir function error; Expected function or variable

Discussion in 'Business Applications' started by anishtain4, Apr 13, 2011.

Thread Status:
Not open for further replies.
  1. anishtain4

    anishtain4 Thread Starter

    Joined:
    Apr 11, 2011
    Messages:
    31
    I wanna make sure if a path exist or not? I'm using this code but it's not working:

    Code:
    If dir("C:\Text Files", vbDirectory) = "" Then
      MsgBox "dir worked"
    End If
    but it lead to a compile error, any idea why?
     
  2. Jimmy the Hand

    Jimmy the Hand

    Joined:
    Jul 28, 2006
    Messages:
    1,223
    How about this one:

    Code:
    Sub test()
        On Error GoTo NoDir
        ChDir "C:\Text Files"
        MsgBox "dir exists"
        Exit Sub
    NoDir:
        MsgBox "dir does not exist"
    End Sub
    
    Jimmy
     
  3. anishtain4

    anishtain4 Thread Starter

    Joined:
    Apr 11, 2011
    Messages:
    31
    Thanks this helped but this question still bothers me why the other way is not working?
    that way is much more common and you may need your default path
     
As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/991175

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice