office交流網--QQ交流群號

Access培訓群:792054000         Excel免費交流群群:686050929          Outlook交流群:221378704    

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

從全路徑文件名中穫取文件名(不含路徑)

2019-12-08 08:00:00
zstmtony
原創
8054

從全路徑文件名中穫取文件名(不含路徑)


方法一:


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
 
分享