【教學】Excel 如何使用巨集快速更改資料夾內所有檔名?

excel 巨集改檔名

excel 巨集改檔名

Step 1 在功能列「開發人員」中程式碼選擇「Visual Basic」
如何開啟「開發人員」?點我看教學


Step 2 輸入程式碼

Sub RenameFilesInFolder()
    Dim MyPath As String
    Dim MyFile As String
    Dim NewName As String
    Dim i As Integer


    MyPath = "C:\YourFolderPath\" ' 更改為資料夾檔案路徑


    If Right(MyPath, 1) <> "\" Then
        MyPath = MyPath & "\"
    End If


    MyFile = Dir(MyPath & "*.*")

    Do While MyFile <> ""

        ' 新的檔案名稱規則,範例在所有檔案前加上「New_」
        NewName = "New_" & MyFile

        Name MyPath & MyFile As MyPath & NewName

        MyFile = Dir
    Loop

    MsgBox "文件名已成功更改!", vbInformation
End Sub

excel 巨集改檔名

Step 3 將資料夾路徑複製,取代上方程式碼中「YourFolderPath」


Step 4 按下執行


excel 巨集改檔名

Step 5 即可將檔案名稱更改

【教學】Excel 如何使用巨集快速更改資料夾內所有檔名?

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *

Scroll to top