jbenfrancis1
New Member
- Joined
- Feb 22, 2022
- Messages
- 11
- Office Version
- 365
- 2016
- Platform
- Windows
I have these two macros working together to grab the file names in a folder and insert them onto sheet "File Names" in column A. I then have a list of Names I want them to be changed to in Column B. However when I run the renamefiles macro I receive File Not Found errror. No files names are duplicates.
VBA Code:
Sub getfile()
Dim myPath As String
Dim myFile As String
myPath = "C:\Users\joe\Desktop\2.23"
myFile = Dir(myPath & "\*.csv")
r = 1
Do While myFile <> ""
Worksheets("File Names").Cells(r, 1).Value = myFile
r = r + 1
myFile = Dir
Loop
End Sub
Code:
Sub RenameFile()
Dim myPath As String
myPath = "C:\Users\joe\Desktop\2.23"
Dim ws As Worksheet
Set ws = Worksheets("File Names")
r = 1
Do Until IsEmpty(ws.Cells(r, 1)) And IsEmpty(ws.Cells(r, 2))
Name myPath & ws.Cells(r, 1).Value As myPath & ws.Cells(r, 2).Value
r = r + 1
Loop
End Sub