office交流網(wǎng)--QQ交流群號(hào)及微信交流群

Access培訓(xùn)群:792054000         Excel免費(fèi)交流群群:686050929          Outlook交流群:221378704    

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

微信交流群(請(qǐng)用微信掃碼)

        

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

2019-12-08 08:00:00
zstmtony
原創(chuàng)
8287

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


方法一:


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 獲取擴(kuò)展名
 

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, "拆分路徑函數(shù)", "無(wú)效的參數(shù)!"
End Select

End Function
 
分享
文章分類
聯(lián)系我們
聯(lián)系人: 王先生
Email: 18449932@qq.com
QQ: 18449932
微博: officecn01
移動(dòng)訪問(wèn)