View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Lillian[_5_] Lillian[_5_] is offline
external usenet poster
 
Posts: 47
Default Trancat file name using VBA

After I run this macro file name update.xls was popup
from the message box, after that how to run your
function, need help.

thanks.

Lillian
-----Original Message-----
Hi, this macro did not mention the loop for sheet1,
sheet2, sheet3, also on each sheet of column B need to

do
the macro, you did not mention to column B at all, how

to
run your macro, do I hight light the column B and run it?


Lillian
-----Original Message-----
It's simple...

Sub djkslajdksla()
MsgBox ExtractFileName(ThisWorkbook.FullName)
End Sub

Function ExtractFileName(fPath As String) As String
Dim i As Long, lcut As Long, llen As Long

i = InStr(i + 1, fPath, "\")
Do While i 0
lcut = i
i = InStr(i + 1, fPath, "\")
Loop

If lcut 0 Then
llen = Len(fPath) - lcut
ExtractFileName = Mid(fPath, lcut + 1, llen)
Else
ExtractFileName = ""
End If
End Function


-----Original Message-----
I have one excel spreed sheet, it have three

worksheet,
they are sheet1, sheet2, sheet3, in each worksheets on
the column B has real long file directory, example:
J:\files\docfiles\amaya01\demand.mcp.wpd, all I need

is
last file name: demand.mcp.wpd, it means I only need

the
file name after the last slash "\", all the column B

has
all the file name but in different directory, another
example:
j:\FILES\DOCFILES\Civil Service\CS-SUBIA\OLGA.SRP, all

I
need is OLGA.SRP file name, so can we write the macro
removed everything before last slash "\".

SO this macro has be in the loop for

sheet1,sheet2,sheet3.

thanks for the help.

Lillian

.

.

.