楼上的比我的好,建议你多学习一下字符串截取函数,right left mid nstr
Text1是文件路径 Text2是提取的文件名
我写的代码如下:
Private Sub Command1_Click()
Dim i As Integer, n As Integer
For i = 1 To Len(Text1)
If Mid(Text1, i, 1) = "\" Then n = i
Next
Text2 = Right(Text1, Len(Text1) - n)
End Sub
楼上几位够费劲的,只需要一行代码:
Text2 = CreateObject("Scripting.FileSystemObject").GetBaseName(Text1)
Private Sub Command1_Click()
Text2 = Mid(Text1, InStrRev(Text1, "\") + 1, InStrRev(Text1, ".") - InStrRev(Text1, "\") - 1)
End Sub
dim a () as string
a=split(text1.text,"\")
a=split(a(ubound(a)),".")
text2.text=a(ubound(a)-1)
Text2 = Mid(Text1, InStrRev(Text1, "\") + 1, Len(Text1))