![]() |
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 |
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 | |
All times are GMT +1. The time now is 08:52 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com