Home>

I want to change all the file names in VBA.
Specifically
xx01.txt → aaa_xx01.txt
xx02.txt → aaa_xx02.txt
xx03.txt → aaa_xx03.txt
xx04.txt → aaa_xx04.txt
xx05.txt → aaa_xx05.txt
I want to change the file name all at once.

Error message

"Run-time error'53&apos ;:
File not found.

Applicable source code

VBA

Public Sub NameChange ()

Dim SourcePath As String
Dim DestinationPath As String
Dim i As Integer
Dim j As Integer

SourcePath ="\\ C: abc \ test \"
DestinationPath ="\\ D: 123 \ test"

j = 1

For i = 1 To 5
Name SourcePath&"xx0"&"j"&".txt"_
As DestinationPath&"aaa_xx0"&"j"&".txt"
j = j + 1
Next i

End Sub

Tried

At first, the variable i was used instead of the variable j to express the file name.
Because it didn't work well, I programmed using variable j, but
I still can't solve it.

Supplemental information (FW/tool version etc.)

The program that renamed only one file worked fine.

Public Sub NameChange ()

Dim SourcePath As String
Dim DestinationPath As String

SourcePath ="\\ C: abc \ test \"
DestinationPath ="\\ D: 123 \ test"

Name SourcePath&"xx01.txt"_
As DestinationPath&"aaa_xx01.txt"

End Sub

vba