office交流网--QQ交流群号

Access培训群:792054000         Excel免费交流群群:686050929          Outlook交流群:221378704    

Word交流群:218156588             PPT交流群:324131555

从全路径文件名中获取文件名(不含路径)

2019-12-08 08:00:00
zstmtony
原创
8079

从全路径文件名中获取文件名(不含路径)


方法一:


Public Function gf_GetFileName(strFullPath As String) As String
 
    Dim splitList As Variant
    splitList = VBA.Split(strFullPath, "")
    gf_GetFileName = splitList(UBound(splitList, 1))
    
End Function



方法二:



'intType=0 获取路径

'intType=1 获取文件名

'intType=2 获取扩展名
 

Public Function SplitstrFullPath(strFullPath As String, intType As Integer) As String

Dim intSplitPos As Integer, intDotPos As Integer

intSplitPos = InStrRev(strFullPath, "/")

intDotPos = InStrRev(strFullPath, ".")

Select Case intType

Case 0

 SplitstrFullPath = Left(strFullPath, intSplitPos - 1)

Case 1

 If intDotPos = 0 Then intDotPos = Len(strFullPath) + 1

 SplitstrFullPath = Mid(strFullPath, intSplitPos + 1, intDotPos - intSplitPos - 1)

Case 2

 If intDotPos = 0 Then intDotPos = Len(strFullPath)

 SplitstrFullPath = Mid(strFullPath, intDotPos + 1)

Case Else

 Err.Raise vbObjectError + 1, "拆分路径函数", "无效的参数!"
End Select

End Function
 
分享