我有一个名为SampleTestFile.ghi
的文本文件。在程序处理完此文件后,它将被重命名并移动到另一个文件夹中。重命名文件时使用的命名约定为*.abc
所以我有文件名(SampleTestfile.ghi
),我有命名约定(*.abc
),但是如何使用VBA将原始文件名转换为已处理的文件名?有没有办法可以说
ProcessFileName = "SampleTestFile.ghi" & "*.abc"
''and get the correct answer of SampleTestFile.abc ?
答案 0 :(得分:1)
ProcessFileName = Replace(sampleTestFileName, ".ghi",".abc")
假设“.ghi”永远不会出现在文件名的中间
使用Mid()
Sub Test()
Dim s
s = "my strange filename.ghi here.ghi"
Debug.Print "original", s
'Method 1 (has a potential problem)
Debug.Print "method 1", Replace(s, ".ghi", ".abc")
'Method 2 (safer)
Mid(s, Len(s) - 3, 4) = ".abc"
Debug.Print "method 2", s
End Sub