VBA Renaming Electronic Files

OilEconomist

Active Member
Joined
Dec 26, 2016
Messages
439
Office Version
  1. 2019
Platform
  1. Windows
Thanks in advance for any suggestions which I will provide feedback.

I am making an Excel file where I place the directory path (Cell B3) of where files that I may want to rename are located.

It first obtains the file names and places them in Column A starting with Row 5.

I then place the new names in Column B starting in Row 5.

I get the error when I try to run the Macro to rename "Run Time Error 53: File not Found"

Code:
Name DirFolderRename & CurrentName As DirFolderRename & NewName


The following is the entire code to rename the files:
Code:
Sub RenameFile()


'Dimensioning
    Dim DirFolderRename As String
    Dim CurrentName As String
    Dim NewName As String
    Dim i As Integer
    
    i = 5
    
    DirFolderRename = Sheets("List").Range("B3").Value
    
    Do While Sheets("List").Cells(i, 1).Text <> "" And Sheets("List").Cells(i, 2).Text <> ""
    
        CurrentName = Sheets("List").Cells(i, 1).Text <> ""
        NewName = Sheets("List").Cells(i, 2).Text <> ""
        Name DirFolderRename & CurrentName As DirFolderRename & NewName
        
        i = 1 + 1
        
    Loop
    
    MsgBox ("Complete")
    
    
End Sub
 
Thanks Fluff as that was a great tip. Whenever I enter the directory, I need to make sure it has a "
" at the end or change the code to where it adds it.
 
Upvote 0

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.

Forum statistics

Threads
1,223,911
Messages
6,175,327
Members
452,635
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top