Trim "\" Value

  • Thread starter Thread starter Todd Huttenstine
  • Start date Start date
T

Todd Huttenstine

Hey guys I have the following value of a variable:

Q:\CS Management Reports\Reports Setup\Administrator
Files\Exported Modules\test.bas

I would like to trim that value to where it only gives me
the value "test.bas"

How do I do this?


Thanx
Todd Huttenstine
 
Try something like

Function GetName(FullPath As String) As String
Dim FileName As Variant
FileName = Split(FullPath, Application.PathSeparator)
FileName = FileName(UBound(FileName))
GetName = FileName
End Function
 
Hi Todd,

Todd said:
Hey guys I have the following value of a variable:

Q:\CS Management Reports\Reports Setup\Administrator
Files\Exported Modules\test.bas

I would like to trim that value to where it only gives me
the value "test.bas"

How do I do this?

since Excel2000 you can use the Split Function:

Dim strText As String
Dim varSplit As Variant

strText = "Q:\CS Management Reports\Reports Setup\AdministratorFiles\Exported Modules\test.bas"
varSplit = VBA.Split(strText, "\")
strText = varSplit(UBound(varSplit))

--
Mit freundlichen Grüssen

Melanie Breden
- Microsoft MVP für Excel -

http://excel.codebooks.de (Das Excel-VBA Codebook)
 
Public Function fileNameOnly(fPth As String) As String
Dim i As Integer, length As Integer, Temp As String

length = Len(fPth)
Temp = ""
For i = length To 1 Step -1
If Mid(fPth, i, 1) = Application.PathSeparator Then
fileNameOnly = Temp
Exit Function
End If
Temp = Mid(fPth, i, 1) & Temp
Next i
fileNameOnly = fPth
End Function
 
strVar = "Q:\CS Management Reports\Reports Setup\Administrator
Files\Exported Modules\test.bas"
strLen = Len(strVar)
slashLoc = InStrRev(strVar, "\")
fileNameLen = strLen - slashLoc
fileName = Right(strVar, fileNameLen)

This works in theory, but I haven't tested it so let me know if it doe
not work. - Piku
 
The code samples that used Split (or VBA.Split) will work for xl2k or higher.
The other code is should work in all versions. (I didn't test, though.)

Split was added in xl2k.
 
Dave said:
The code samples that used Split (or VBA.Split) will work for xl2k or higher.
The other code is should work in all versions. (I didn't test, though.)

Split was added in xl2k.

And I think the same restriction applies to the InStrRev sample
 
Back
Top