Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Dir problems

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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,337
Default Dir problems

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

"Jim" wrote in message
...
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




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 860
Default Dir problems

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.

--
Regards,

Jake Marx
www.longhead.com


Jim wrote:
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


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problems with ngs T. Valko Excel Worksheet Functions 2 January 6th 10 12:05 AM
aauugghhh...#div/o problems & various average formula problems acbel40 Excel Worksheet Functions 5 October 19th 09 05:00 PM
Problems Kay Excel Worksheet Functions 2 May 22nd 09 02:37 AM
STILL Having VBA Problems!!!!!!! Elise148 Excel Discussion (Misc queries) 9 July 3rd 07 08:40 PM
VBA problems Andrew Clark Excel Discussion (Misc queries) 3 March 16th 05 09:33 PM


All times are GMT +1. The time now is 01:55 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"