If A Directory Exists

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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
 
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top