2017-05-30 208 views
1

我需要部分重命名Excel表格的帮助。 我有大约40这些需要每月部分重命名。部分重命名多个Excel文件

对于如:

 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

你到目前为止尝试过什么?当你尝试时发生了什么?请包括您使用的代码,并说明您遇到的问题,否则我们不会“帮助”您,我们只需自己完成所有工作。 – YowE3K

回答

0

EDIT1:使用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