本文介绍了VBA通过添加空格来重命名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在文档名称之间添加一个空格.但是,代码无法通过 IF True
行.
I want to add a space in between a document name. However the code can't pass through the IF True
line.
具有以下随机名称的文档名称:
Document name having random name as below:
INV500TAT1234 Rev 1 Form_Health.pdf
希望它是
INV500 TAT1234 Rev 1 Form_Health.pdf #with a space in between 500 & TAT
请注意,某些文档已经包含 INV500 TAT
,所以我写了 if
跳过它们
Note that some of the document does already contain INV500 TAT
, so I wrote the if
to skip them
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
推荐答案
这将在每个以 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
这篇关于VBA通过添加空格来重命名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!