跳到主要内容

如何在Excel中重命名一个文件夹的多个文件?

可能我们大多数人都遭受这个问题的困扰,我们需要在一个文件夹中重命名多个文件,如果该文件夹中有成百上千个文件,那么一个文件名一个一个地重命名会使我们发疯。 我们有什么好的职能来处理这项任务吗?

使用 kutools for Excel 列出工作表中特定文件夹中的所有文件名

使用VBA代码重命名Excel中一个文件夹的多个文件


如果有多个文件要重命名,首先,您可以在工作表的列中列出旧文件名,然后输入要替换的新文件名。 要快速列出工作表中的所有文件,您可以使用 Kutools for Excel文件名列表 效用。

安装后 Kutools for Excel,请执行以下操作: 立即免费下载Kutools for Excel )

1。 点击 Kutools 加 > 进出口 > 文件名列表,请参见屏幕截图:

2。 在 文件名列表 对话框,单击 文档重命名多个文件-1 按钮选择要列出文件的文件夹,然后单击 所有文件 来自 档案类型,请参见屏幕截图:

文档重命名多个文件-1

3。 然后点击 OK 按钮,所有文件名都已列在新工作表的列中,以及一些文件属性,现在,您可以删除其他不需要的列,而只保留 文件名 列,请参见屏幕截图:

文档重命名多个文件-1

单击以了解有关此文件名列表功能的更多信息…

立即免费下载Kutools for Excel


在A列中列出所有原始文件名后,您应在B列中输入新文件名,如以下屏幕截图所示:

文档重命名多个文件-1

在这里,我将讨论一个VBA代码,该代码可以帮助您立即用新文件名替换旧文件名。 请执行以下步骤:

1。 按住 ALT + F11 键,然后打开 Microsoft Visual Basic应用程序窗口.

2。 点击 插页 > 模块,然后将以下宏粘贴到 模块窗口.

VBA代码:重命名文件夹中的多个文件

Sub RenameFiles()
'Updateby20141124
Dim xDir As String
Dim xFile As String
Dim xRow As Long
With Application.FileDialog(msoFileDialogFolderPicker)
    .AllowMultiSelect = False
If .Show = -1 Then
    xDir = .SelectedItems(1)
    xFile = Dir(xDir & Application.PathSeparator & "*")
    Do Until xFile = ""
        xRow = 0
        On Error Resume Next
        xRow = Application.Match(xFile, Range("A:A"), 0)
        If xRow > 0 Then
            Name xDir & Application.PathSeparator & xFile As _
            xDir & Application.PathSeparator & Cells(xRow, "B").Value
        End If
        xFile = Dir
    Loop
End If
End With
End Sub

3。 粘贴代码后,请按 F5 键来运行此代码,然后在 浏览 窗口中,选择要在其中更改文件名的文件夹,请参见屏幕截图:

文档重命名多个文件-1

4。 然后点击 OK,所有旧文件名都立即被新文件名替换。 查看屏幕截图:

文档重命名多个文件-1 2 文档重命名多个文件-1

笔记:

1.当您列出新旧文件名时,必须包含文件扩展名。

2.在上面的代码中,参考 答: 表示要重命名的旧文件名列表,并引用 B 包含您要使用的新文件名,您可以根据需要进行更改


Kutools for Excel:具有300多个方便的Excel加载项,可以在30天内免费试用,没有任何限制。 立即下载并免费试用!

相关文章:

如何从Excel中的一系列单元格创建序列工作表?

如何在Excel中重命名多个工作表?

最佳办公生产力工具

🤖 Kutools 人工智能助手:基于以下内容彻底改变数据分析: 智能执行   |  生成代码  |  创建自定义公式  |  分析数据并生成图表  |  调用 Kutools 函数...
热门特色: 查找、突出显示或识别重复项   |  删除空白行   |  合并列或单元格而不丢失数据   |   不使用公式进行四舍五入 ...
超级查询: 多条件VLookup    多值VLookup  |   跨多个工作表的 VLookup   |   模糊查询 ....
高级下拉列表: 快速创建下拉列表   |  依赖下拉列表   |  多选下拉列表 ....
列管理器: 添加特定数量的列  |  移动列  |  切换隐藏列的可见性状态  |  比较范围和列 ...
特色功能: 网格焦点   |  设计图   |   大方程式酒吧    工作簿和工作表管理器   |  资源库 (自动文本)   |  日期选择器   |  合并工作表   |  加密/解密单元格    按列表发送电子邮件   |  超级筛选   |   特殊过滤器 (过滤粗体/斜体/删除线...)...
前 15 个工具集12 文本 工具 (添加文本, 删除字符,...)   |   50+ 图表 类型 (甘特图,...)   |   40+ 实用 公式 (根据生日计算年龄,...)   |   19 插入 工具 (插入二维码, 从路径插入图片,...)   |   12 转化 工具 (小写金额转大写, 货币兑换,...)   |   7 合并与拆分 工具 (高级组合行, 分裂细胞,...)   |   ... 和更多

使用 Kutools for Excel 增强您的 Excel 技能,体验前所未有的效率。 Kutools for Excel 提供了 300 多种高级功能来提高生产力并节省时间。  单击此处获取您最需要的功能...

产品描述


Office Tab 为 Office 带来选项卡式界面,让您的工作更加轻松

  • 在Word,Excel,PowerPoint中启用选项卡式编辑和阅读,发布者,Access,Visio和Project。
  • 在同一窗口的新选项卡中而不是在新窗口中打开并创建多个文档。
  • 每天将您的工作效率提高50%,并减少数百次鼠标单击!
Comments (38)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Great! it work for me
This comment was minimized by the moderator on the site
The above stated code does not detect native language file names in Hindi or Marathi - example "HIN-MALE-CH - 7 - कार"
Here the code does not detect "कार"
Any way to handle this issue?
This comment was minimized by the moderator on the site
Sziasztok!
Ha kép nevébe "/" jelet akarok rakni, akkor min kell változtatnom?
Ha benne van a "/" jel akkor nekem nem működik.

Köszönöm
Andor
This comment was minimized by the moderator on the site
Hello, Benedeczki,

Under normal circumstances, the file name cannot contain the /\:*?<>” symbol, so if your picture name contains the / symbol, the code cannot run normally.
You'd better to remove the / symbol from the file name.
Thank you!
This comment was minimized by the moderator on the site
wow, useful and very helpful. BIG THANKS :)
This comment was minimized by the moderator on the site
Sub RenameMultipleFiles()
With Application.FileDialog(msoFileDialogFolderPicker)
.AllowMultiSelect = False
If .Show = -1 Then
selectDirectory = .SelectedItems(1)
dFileList = Dir(selectDirectory & Application.PathSeparator & "*")

Do Until dFileList = ""
curRow = 0
On Error Resume Next
curRow = Application.Match(dFileList, Range("A:A"), 0)
If curRow > 0 Then
Name selectDirectory & Application.PathSeparator & dFileList As _
selectDirectory & Application.PathSeparator & Cells(curRow, "B").Value
End If

dFileList = Dir
Loop
End If
End With
End Sub

this formula does not rename1st document
This comment was minimized by the moderator on the site
Love this so much! Is there a way to use Kutools to edit metadata tags for music similar to this with filenames? Would love being able to mass edit song tags through Excel rather than on iTunes or other third party song tag editors. Thank you!
This comment was minimized by the moderator on the site
okay Thank you
This comment was minimized by the moderator on the site
Hello. I did this for a couple of files and it worked successfully. The next few files i tried, did not work. There were a few formulas added to the new names, could that be the issue?
This comment was minimized by the moderator on the site
Very helpful. Thank you!
This comment was minimized by the moderator on the site
great, worked great for me
There are no comments posted here yet
Load More
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations