Trim "\" Value

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
 
J

Juan Pablo Gonzalez

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
 
M

Melanie Breden

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)
 
H

Hawk

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
 
P

pikus

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
 
D

Dave Peterson

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.
 
S

Steve Garman

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
 

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

Similar Threads

Importing all components in a folder 1
Trim Blanks 5
LastName, FirstName format 2
Add Workbook with specified name 2
Browse For Folder start directory 2
Function variables 7
Renaming a standard module 5
Time Stamp 3

Top