从全路径文件名中获取文件名(不含路径)
方法一:
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