我想在文档名称之间添加一个空格。但是,代码无法通过 IF True
行。
文档名称具有随机名称,如下:
INV500TAT1234 Rev 1 Form_Health.pdf
希望它是:
INV500 TAT1234 Rev 1 Form_Health.pdf #with a space in between 500 & TAT
请注意,某些文档已经包含 INV500 TAT
,因此我编写了 if
来跳过它们
Sub Rename_Space()
Dim ffile As Variant, path As String
path = "C:\Users\me\Desktop\Rename\"
ffile = Dir(path)
While ffile <> ""
If ffile = "INV500TAT*" Then
old_name = path & ffile
new_name = path & "INV500 TAT*"
Name old_name As new_name
End If
ffile = Dir
Wend
End Sub
最佳答案
这将在每个以 INV500TAT
开头的文件名中的 500
和 TAT
之间留出一个空格。
Sub Rename_Space()
Dim ffile As Variant, path As String
path = "C:\Users\me\Desktop\Rename\"
ffile = Dir(path)
While ffile <> ""
Debug.Print ffile
If Left(ffile, 9) = "INV500TAT" Then
old_name = path & ffile
new_name = path & Left(ffile, 6) & " " & Mid(ffile, 7, Len(ffile))
Name old_name As new_name
End If
ffile = Dir
Wend
End Sub
关于excel - VBA通过添加空格重命名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65715270/