【问题标题】:Partially renaming multiple Excel files部分重命名多个 Excel 文件
【发布时间】:2017-10-31 13:09:47
【问题描述】:

我需要有关部分重命名 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 代码似乎都完全更改了名称。我希望这些文件具有各自的文件名并成功地部分重命名它们。

非常感谢您的帮助。

【问题讨论】:

  • 到目前为止你尝试过什么?当你尝试它时发生了什么?请附上您使用的代码,以及您遇到的问题的描述,否则我们不会“帮助”您,我们只能自己完成所有工作。

标签: vba excel


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2014-01-06
    • 1970-01-01
    • 2019-06-08
    • 1970-01-01
    • 1970-01-01
    • 2013-12-05
    • 2021-07-13
    • 2020-01-29
    • 1970-01-01
    相关资源
    最近更新 更多