ファイル名を返す関数の サンプルです。
ファイルの先頭に数値との事でしたが、
ファイル名にて、並べ替えを行う際に 判りづらくなるので、
ファイルベース名 と、拡張子の間に、『_00』形式の数値を入れています。
ファイルベース名 / 拡張子 を取得するのに
FSO を使用していますので、参照設定を行ってください。
また、メールアイテム複数に対しての様なので、
FSOの変数宣言をモジュールレベルとして、
関数GetFileName内での 変数の 生成/破棄 を行わないようにしています。
Option Explicit
'要参照設定 Microsoft Scripting RunTime
Dim FSO As Scripting.FileSystemObject
Function GetFileName(strPath) As String
'引数 : ファイルフルパス
'戻値 : フォルダ名\ファイルベース名_00.拡張子
' 00 は、0〜99 まで。 99が存在する場合には、99となる
Dim i As Long
Dim strFilePath
Dim strFolder As String
Dim strBaseName As String
Dim strExtensionName As String
strFilePath = strPath
If FSO.FileExists(strFilePath) = True Then
strFolder = FSO.GetParentFolderName(strFilePath)
strBaseName = FSO.GetBaseName(strFilePath)
strExtensionName = FSO.GetExtensionName(strFilePath)
For i = 1 To 1
strFilePath = (strFolder & "\" & strBaseName & Format(i, "\_00\.") & strExtensionName)
If FSO.FileExists(strFilePath) = False Then
Exit For
End If
Next
End If
GetFileName = strFilePath
End Function
Sub test()
Set FSO = CreateObject("Scripting.FileSystemObject")
MsgBox GetFileName("C:\DATA\ファイル名.xls")
Set FSO = Nothing
End Sub