Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default CurDir, ChDrive, ChDir error questions

In excel 2003 windows xp I have been using the following code for a
long time successfully:

sub ForceDirectoryOpenSave

Dim strStartingDirectory As String
strStartingDirectory = CurDir
ChDrive "T"
ChDir "T:\xx\xy\xu\xa"

' code for whatever application.get___ i need

ChDrive strStartingDirectory
ChDir strStartingDirectory

end sub

Recently I have started having errors on the line;

ChDrive strStartingDirectory

It seems to happen randomly ie not every time the users have that
code, or even every time the machine is restarted ect and if you rerun
the sub (or skip JUST that line in subs without full error handling)
it works. After reading through groups I assume that the system admins
(i work at a large public university) have started controlling some
things with UNC paths and when excel last used a UNC path it errors.
All of our data/workspace is on the T drive so I dont have to be able
to "point" to UNC paths for the dialogs. I just am tired of subs being
dropped out of randomly and having to figure out how to get the user
back to where they need to be to continue working without negative
effects.
What are the "consequences" (if any) of not changeing the Drive back
to match the starting directory but changing the directory back? Or
using OnError Resume Next to "shut off" my regular error handling for
these instances to stop this from dropping users out of subs (then
after that line using OnError Goto ErrorHandler to "turn on" normal
error handling again) so that when excel is pointing to a mapped drive
it still changes it back?

thanks
john
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default CurDir, ChDrive, ChDir error questions

It may be that the start drive is not mapped to a letter, a UNC path as they
say. It's better I think to use this Windows API call, which works with
mapped and unmapped paths, and changes drive and path in one call.

Add at the top of your modules:

Declare Function SetCurrentDirectoryA Lib "KERNEL32" (ByVal lpPathName As
String) As Long

then in your code:

strStartingDirectory = CurDir
SetCurrentDirectoryA "T:\xx\xy\xu\xa"

' code for whatever application.get___ i need

SetCurrentDirectoryA strStartingDirectory



"goaljohnbill" wrote in message
...
In excel 2003 windows xp I have been using the following code for a
long time successfully:

sub ForceDirectoryOpenSave

Dim strStartingDirectory As String
strStartingDirectory = CurDir
ChDrive "T"
ChDir "T:\xx\xy\xu\xa"

' code for whatever application.get___ i need

ChDrive strStartingDirectory
ChDir strStartingDirectory

end sub

Recently I have started having errors on the line;

ChDrive strStartingDirectory

It seems to happen randomly ie not every time the users have that
code, or even every time the machine is restarted ect and if you rerun
the sub (or skip JUST that line in subs without full error handling)
it works. After reading through groups I assume that the system admins
(i work at a large public university) have started controlling some
things with UNC paths and when excel last used a UNC path it errors.
All of our data/workspace is on the T drive so I dont have to be able
to "point" to UNC paths for the dialogs. I just am tired of subs being
dropped out of randomly and having to figure out how to get the user
back to where they need to be to continue working without negative
effects.
What are the "consequences" (if any) of not changeing the Drive back
to match the starting directory but changing the directory back? Or
using OnError Resume Next to "shut off" my regular error handling for
these instances to stop this from dropping users out of subs (then
after that line using OnError Goto ErrorHandler to "turn on" normal
error handling again) so that when excel is pointing to a mapped drive
it still changes it back?

thanks
john


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default CurDir, ChDrive, ChDir error questions

On Jan 13, 5:44*am, "Jim Rech" wrote:
.....
Add at the top of your modules:

Declare Function SetCurrentDirectoryA Lib "KERNEL32" (ByVal lpPathName As
String) As Long

then in your code:

* strStartingDirectory = CurDir
* SetCurrentDirectoryA "T:\xx\xy\xu\xa"

* ' *code for whatever application.get___ i need

* SetCurrentDirectoryA strStartingDirectory

....

So it will work properly with just the declare function line? So does
that mean the additional lines in responses to other chdrive problems
is checking/error handling for "selecting" a UNC drive?
A solution where i add a line to each module and change 3 lines with 2
at each usage is better than what I was worried I would need to do
after searching.

Thanks
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
ChDir and ChDrive Conan Kelly Excel Programming 2 December 24th 08 09:26 PM
Workaround for ChDir/CurDir when path has unicode characters keepITcool Excel Programming 4 July 10th 07 04:56 PM
ChDrive error (server path) Marcotte A Excel Programming 6 November 2nd 05 07:16 PM
Problems with ChDrive and ChDir Sophie Excel Programming 5 December 2nd 04 04:33 PM
Problems with ChDrive, ChDir Sophie Excel Programming 4 November 29th 04 09:35 AM


All times are GMT +1. The time now is 08:53 AM.

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

About Us

"It's about Microsoft Excel"