I'm trying to extract the name of a sub directory from a directory path.
Path - c:\thomsons\stuff\exciting.xls
Using the following code (picked up from Tek Tips by Supra - cheers) I'm able to extract the full directory path and also the filename but what I am wanting to do is extract the sub directory 'Stuff'
Private Sub Form_Open()
Dim FullPath As String
Dim FileName As String
Dim FileDir As String
FullPath = "c:\thomsons\stuff\exciting.xls"
FileName = FileFromPath(FullPath)
FileDir = DirFromPath(FullPath)
MsgBox "Full Path: " & FullPath & vbCrLf & _
"File Name: " & FileName & vbCrLf & _
"Directory: " & FileDir
End Sub
Private Function DirFromPath(strPath As String)
Dim Pos As Long
Pos = InStrRev(strPath, "\"
DirFromPath = Left(strPath, Pos)
End Function
Private Function FileFromPath(strPath As String)
Dim Pos As Long
Pos = InStrRev(strPath, "\"
FileFromPath = Right(strPath, Len(strPath) - Pos)
End Function
Cheers,
ST
Path - c:\thomsons\stuff\exciting.xls
Using the following code (picked up from Tek Tips by Supra - cheers) I'm able to extract the full directory path and also the filename but what I am wanting to do is extract the sub directory 'Stuff'
Private Sub Form_Open()
Dim FullPath As String
Dim FileName As String
Dim FileDir As String
FullPath = "c:\thomsons\stuff\exciting.xls"
FileName = FileFromPath(FullPath)
FileDir = DirFromPath(FullPath)
MsgBox "Full Path: " & FullPath & vbCrLf & _
"File Name: " & FileName & vbCrLf & _
"Directory: " & FileDir
End Sub
Private Function DirFromPath(strPath As String)
Dim Pos As Long
Pos = InStrRev(strPath, "\"
DirFromPath = Left(strPath, Pos)
End Function
Private Function FileFromPath(strPath As String)
Dim Pos As Long
Pos = InStrRev(strPath, "\"
FileFromPath = Right(strPath, Len(strPath) - Pos)
End Function
Cheers,
ST