ChDir Error

S

scain2004

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
 
J

Jim Rech

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
|
| 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?action=getinfo&userid=7051
| View this thread: http://www.excelforum.com/showthread.php?threadid=275377
|
 

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