Subclassing ChDir

Subclassing ChDir

If your application’s current directory is D:OldDir, the callChDir(C:NewDir) will change the C Drive’s default directory toNewDir, but the application’s current directory will remain D:OldDir.It seemed to me that ChDir should change the application’s currentdirectory in all cases. This subclassed ChDir subroutine handlesdrive changes, too:

 Sub ChDir(Path As String)        Dim TargetDrive As String        ' if 2nd and 3rd letters of target         ' are ":"        If Mid(Path, 2, 2) = ":" Then                TargetDrive = Left(Path, 3)                If TargetDrive  _                        Left(CurDir, 3) Then                        ChDrive TargetDrive                End If        End If' Call VB's ChDir function        VBA.ChDir PathEnd Sub


Share the Post: