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

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

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

微信交流群(請用微信掃碼)

        

從全路徑文件名中穫?cè)∥募ú缓窂剑?/h1>
2019-12-08 08:00:00
zstmtony
原創(chuàng)
8288

從全路徑文件名中穫?cè)∥募ú缓窂剑?/p>


方法一:


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 穫?cè)÷窂?
'intType=1 穫?cè)∥募?
'intType=2 穫?cè)U(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ù)", "無效的蔘數(shù)!"
End Select

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