Dir problems

J

Jim

I had a problem with a tiny bit of code at work today and
hoped one of you may have the answer.
In my department, our IT guys are so clever that some
people have the departments files stored on the G:\
drive, and some on the K:\ (dont ask).
Therefore, at the start of alot of my code I have to
obtain the correct path of the person running the code.
To do this, I wrote something similar to this (this is
from memery):

mydir = Dir("K:\", vbDirectory)
If mydir > "" Then Path = "K:\"
Else path = "G:\"

This works fine if the person running the code has the
departments files on the K:\ drive, but if they are on
the G:\ drive it gets a runtime error (68 if I remember
rightly) probably because the K:\ doesnt exist!

How can I prevent this error from happening? Apart from
sack our LAN Administration guys!

Cheers
Jim
 
D

Don Guillett

Untested but try
on error resume next as the line above mydir or below mydir
 
J

Jake Marx

Hi Jim,

You can use UNC paths for most things, so I would recommend using those in
your application instead of drive letters. That way, your app isn't reliant
on whether a drive is mapped or not. For example, instead of using
Workbooks.Open "K:\myfolder\test.xls", you could use Workbooks.Open
"\\servername\myfolder\test.xls".

This assumes that the mapped drives on each user's machine actually points
to the same network drive. If not, you may have to do it the way you are
and trap for the error. Look under VB help for "On Error" and that should
get you started.
 

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

Top