+ Reply to Thread
Results 1 to 3 of 3

If A Directory Exists

  1. #1
    achidsey
    Guest

    If A Directory Exists

    Excel Experts,

    My code needs to open a file in a network directory named "Statements".

    For me, Statements is under my "T:" drive, but for other users, it's
    somewhere else.

    I generally run this code, so I don't want to ask for a drive letter every
    time. What I want my code to do is ask, "is the directory "T:\Statements"
    available?"

    If the code is running on my machine, the above question will generate Yes
    and the code will continue to the Then branch.

    If someone else whose Statements folder is under another drive letter, the
    question will generate No, and my code will go to the Else branch.

    My code will be something like:

    If T:\Statements Exists Then

    Workbooks.Open ("T:\Statements\netcap.xls")

    Else

    Letter = InputBox("Enter the Drive Letter for the Statements folder")

    Workbooks.Open(Letter & ":\Statements\netcap.xls")

    End If

    My question is, How do I ask "If T:\Statements exists"?

    Thanks,
    Alan


    --
    achidsey

  2. #2
    Tim Williams
    Guest

    Re: If A Directory Exists

    Use the UNC path when accessing a network folder
    Of course, you should still check the file exists...

    ************************************************
    Const F_PATH as string="\\servername\foldername\netcap.xls"

    if Dir(F_PATH)<>"" then
    Workbooks.Open (F_PATH )
    'do stuff
    end if
    ************************************************

    Tim

    "achidsey" <chidsey2@hotmail.com(notmorespam)> wrote in message
    news:6A0848B4-55B6-43C1-8D57-749F1CF3A7B5@microsoft.com...
    > Excel Experts,
    >
    > My code needs to open a file in a network directory named "Statements".
    >
    > For me, Statements is under my "T:" drive, but for other users, it's
    > somewhere else.
    >
    > I generally run this code, so I don't want to ask for a drive letter every
    > time. What I want my code to do is ask, "is the directory "T:\Statements"
    > available?"
    >
    > If the code is running on my machine, the above question will generate Yes
    > and the code will continue to the Then branch.
    >
    > If someone else whose Statements folder is under another drive letter, the
    > question will generate No, and my code will go to the Else branch.
    >
    > My code will be something like:
    >
    > If T:\Statements Exists Then
    >
    > Workbooks.Open ("T:\Statements\netcap.xls")
    >
    > Else
    >
    > Letter = InputBox("Enter the Drive Letter for the Statements
    > folder")
    >
    > Workbooks.Open(Letter & ":\Statements\netcap.xls")
    >
    > End If
    >
    > My question is, How do I ask "If T:\Statements exists"?
    >
    > Thanks,
    > Alan
    >
    >
    > --
    > achidsey




  3. #3
    Jim Thomlinson
    Guest

    RE: If A Directory Exists

    Instead of using the drive letter why not jsut use the complete drive
    mapping, something like...

    Workbooks.Open ("\\myServer\myDirectory\Statements\netcap.xls")

    You can ge the \\myserver\mydirectory from lookin in Windows explorer at the
    drive mapping next to the drive letter.
    --
    HTH...

    Jim Thomlinson


    "achidsey" wrote:

    > Excel Experts,
    >
    > My code needs to open a file in a network directory named "Statements".
    >
    > For me, Statements is under my "T:" drive, but for other users, it's
    > somewhere else.
    >
    > I generally run this code, so I don't want to ask for a drive letter every
    > time. What I want my code to do is ask, "is the directory "T:\Statements"
    > available?"
    >
    > If the code is running on my machine, the above question will generate Yes
    > and the code will continue to the Then branch.
    >
    > If someone else whose Statements folder is under another drive letter, the
    > question will generate No, and my code will go to the Else branch.
    >
    > My code will be something like:
    >
    > If T:\Statements Exists Then
    >
    > Workbooks.Open ("T:\Statements\netcap.xls")
    >
    > Else
    >
    > Letter = InputBox("Enter the Drive Letter for the Statements folder")
    >
    > Workbooks.Open(Letter & ":\Statements\netcap.xls")
    >
    > End If
    >
    > My question is, How do I ask "If T:\Statements exists"?
    >
    > Thanks,
    > Alan
    >
    >
    > --
    > achidsey


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1