我需要有关部分重命名excel表的帮助。 我有大约40个这些需要每月部分重命名。
例如:
2017_06 Jun QFR Planning File,
2017_06 Jun QFR Analytics File,
2017_06 Jun QFR Customer Service File
需要重命名为
2017_07 Jul QCR Planning File
2017_07 Jul QCR Analytics File
2017_07 Jul QCR Customer Service File .
请帮我自动化。我尝试在线查看,但每个VBA代码似乎都完全改变了名称。我希望文件具有各自的文件名,并成功部分重命名。
非常感谢您的帮助。
答案 0 :(得分:0)
编辑1:使用Name As
声明
您可以使用Name As
这样的方法:
'/* Syntax: Name [oldfilename] As [newfilename] */
'/* where oldfilename and newfilename are full file paths */
Name "C:\Test\2017_06 Jun QFR Planning.xlsx" As "C:\Test\2017_06 Jun QCR Planning.xlsx"
如果你有很多文件,那么你可以加入一个循环。
Dim xlFile As Variant
Dim nFile As String
xlFile = Dir("C:\Test\*.xls*") '/* Folder that contains the files */
Do While xlFile <> "" '/* check if anything is returned */
If InStr(xlFile, "QFR") <> 0 Then '/* check if there is 'QFR' in the filename
nFile = VBA.Replace(xlFile, "QFR", "QCR") '/* replace if there is */
Name xlFile As nFile '/* rename the file */
End If
xlFile = Dir '/* Test for more */
Loop