跳到主要內容

如何在Excel中重命名一個文件夾的多個文件?

可能我們大多數人都遭受這個問題的困擾,因為我們需要在一個文件夾中重命名多個文件,如果該文件夾中有成百上千個文件,那麼一一重命名文件名會使我們發瘋。 我們有什麼好的職能來處理這項任務嗎?

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

使用VBA代碼重命名Excel中一個文件夾的多個文件


如果有多個文件要重命名,首先,您可以在工作表的列中列出舊文件名,然後輸入要替換的新文件名。 要快速列出工作表中的所有文件,您可以使用 Excel的Kutools文件名列表 效用。

安裝後 Excel的Kutools,請執行以下操作: 立即免費下載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 包含您要使用的新文件名,您可以根據需要進行更改


Excel的Kutools:具有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選項卡為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