- ©«¤l
- 109
- ¥DÃD
- 2
- ºëµØ
- 0
- ¿n¤À
- 114
- ÂI¦W
- 0
- §@·~¨t²Î
- Win7 Win10
- ³nÅ骩¥»
- Office 2019 WPS
- ¾\ŪÅv
- 20
- ©Ê§O
- ¨k
- ¨Ó¦Û
- ²`¦`
- µù¥U®É¶¡
- 2013-2-2
- ³Ì«áµn¿ý
- 2024-11-6
|
¦^´_ 6# modelcrazyer
¦pªG§A¬On±q¸ô®|¤¤¨ú¥X¤åÀɦWªº¸Ü¡A°e§A¤@¦n¥Î¤@ÂIªº¨ç¼Æ¡A³oÓµ{¦¡ªº¯SÂI¬O®e¿ù©Ên¦n¤@¨Ç¡G- #If VBA7 Then
- Private Declare PtrSafe Function PathRemoveBackslashW Lib "shlwapi.dll" (ByVal pszPath As LongPtr) As Long
- Private Declare PtrSafe Function PathStripPathW Lib "shlwapi.dll" (ByVal pszPath As LongPtr) As Long
- Private Declare PtrSafe Function PathRemoveExtensionW Lib "shlwapi.dll" (ByVal pszPath As LongPtr) As Long
- Private Declare PtrSafe Function lstrlenW Lib "kernel32.dll" (ByVal lpString As LongPtr) As Long
- #Else
- Private Declare PtrSafe Function PathRemoveBackslashW Lib "shlwapi.dll" (ByVal pszPath As Long) As Long
- Private Declare PtrSafe Function PathStripPathW Lib "shlwapi.dll" (ByVal pszPath As Long) As Long
- Private Declare PtrSafe Function PathRemoveExtensionW Lib "shlwapi.dll" (ByVal pszPath As Long) As Long
- Private Declare PtrSafe Function lstrlenW Lib "kernel32.dll" (ByVal lpString As Long) As Long
- #End If
- Public Function ExtractFileName(ByVal FileName As String, Optional ByVal ExtensionReturn As Boolean = True) As String
- Dim I As Long
- Dim strPath As String
-
- #If VBA7 Then
- Dim ptrFileName As LongPtr
- #Else
- Dim ptrFileName As Long
- #End If
-
- FileName = Trim$(FileName) & String(5, vbNullChar)
- ptrFileName = StrPtr(FileName)
- PathRemoveBackslashW ptrFileName
- PathStripPathW ptrFileName
- If Not ExtensionReturn Then PathRemoveExtensionW ptrFileName
- I = lstrlenW(ptrFileName)
- If I > 0 Then ExtractFileName = Trim$(Left$(FileName, I))
- End Function
½Æ»s¥N½X ¤U±ªºµ{¦¡¬O´ú¸Õ¥Îªº¡G- Sub Test()
- Debug.Print ExtractFileName("K:\aaaa\bbbb\AAAA.xlsx ", False)
- Debug.Print ExtractFileName("K:\aaaa\bbbb\AAAA.01.xlsx ", False)
- Debug.Print ExtractFileName("K:\aaaa\bbbb\AAAA\ ", False)
- Debug.Print ExtractFileName("K:\aaaa\bbbb\AAAA", False)
-
- Debug.Print ExtractFileName("K:\aaaa\bbbb\AAAA.xlsx ", True)
- Debug.Print ExtractFileName("K:\aaaa\bbbb\AAAA.01.xlsx ", True)
- End Sub
½Æ»s¥N½X |
|