#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default ChDir Error


I need to code for the possibility that a path was removed from th
system.

If the code is looking for a path that not longer exists, how to I cod
to move past the error and open the dialog?



Code
-------------------

On Error Resume Next
Set wb = Workbooks(cwb)
On Error GoTo 0
If wb Is Nothing Then
If Not GetSetting("PJL", "Startup", "wbPath") = "" Then
Sheets("Admin").Range("CalPath") = GetSetting("PJL", "Startup", "wbPath")
ChDrive Sheets("Admin").Range("CalPath")
ChDir Sheets("Admin").Range("CalPath")
End If
fileName = Application.GetOpenFilename("Excel Files (*.xls),*.xls)", , _
"Please choose a Production Schedule workbook to open")

cwb = ParsePath(fileName, "FILE_ONLY")
wbPath = ParsePath(fileName, "PATH_ONLY")
Sheets("Admin").Range("CalPath") = wbPath
SaveSetting appname:="PJL", section:="Startup", _
key:="wbPath", setting:=wbPath
Sheets("Admin").Range("CalName") = cwb
Set wb = Workbooks.Open(wbPath & cwb)
End If

-------------------

--
scain200
-----------------------------------------------------------------------
scain2004's Profile: http://www.excelforum.com/member.php...nfo&userid=705
View this thread: http://www.excelforum.com/showthread.php?threadid=27537

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,718
Default ChDir Error

You could check the existence of a directory like this:

Sub Demo()
MsgBox DirGood("c:\a")
End Sub

Function DirGood(DirPath) As Boolean
If Right(DirPath, 1) < "\" Then
DirPath = DirPath & "\"
End If
DirGood = (Dir(DirPath & "NUL") = "NUL")
End Function


--
Jim Rech
Excel MVP
"scain2004" wrote in message
...
|
| I need to code for the possibility that a path was removed from the
| system.
|
| If the code is looking for a path that not longer exists, how to I code
| to move past the error and open the dialog?
|
|
|
| Code:
| --------------------
|
| On Error Resume Next
| Set wb = Workbooks(cwb)
| On Error GoTo 0
| If wb Is Nothing Then
| If Not GetSetting("PJL", "Startup", "wbPath") = "" Then
| Sheets("Admin").Range("CalPath") = GetSetting("PJL", "Startup", "wbPath")
| ChDrive Sheets("Admin").Range("CalPath")
| ChDir Sheets("Admin").Range("CalPath")
| End If
| fileName = Application.GetOpenFilename("Excel Files (*.xls),*.xls)", , _
| "Please choose a Production Schedule workbook to open")
|
| cwb = ParsePath(fileName, "FILE_ONLY")
| wbPath = ParsePath(fileName, "PATH_ONLY")
| Sheets("Admin").Range("CalPath") = wbPath
| SaveSetting appname:="PJL", section:="Startup", _
| key:="wbPath", setting:=wbPath
| Sheets("Admin").Range("CalName") = cwb
| Set wb = Workbooks.Open(wbPath & cwb)
| End If
|
| --------------------
|
|
| --
| scain2004
| ------------------------------------------------------------------------
| scain2004's Profile:
http://www.excelforum.com/member.php...fo&userid=7051
| View this thread: http://www.excelforum.com/showthread...hreadid=275377
|


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 not accepting string for path Alan Excel Programming 1 October 13th 04 06:18 PM
Automation Error, Unknown Error. Error value - 440 Neo[_2_] Excel Programming 0 May 29th 04 05:26 AM
Links and Chdir Hansol Excel Programming 3 April 17th 04 08:52 PM
application.dialogs(xlDialogSaveAs) AND CHDIR Jules[_2_] Excel Programming 1 September 3rd 03 08:27 PM


All times are GMT +1. The time now is 04:06 PM.

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"