Good Afternoon Community,
I'm trying to create a macro that renames 125 PDF files that are in a specific folder C: ... I want it to replace the name that is in my column B ... Type get the PDFs in the folder then rename them accordingly my spreadsheet does anyone know how to do this I did several searches and so far I have not achieved anything.
Thanks for the help anyway
It is a bit tense to practice language change since I study Java and started doing VBA. I did what I knew, but I got a lot of search data on google.
In my code, I am having to inform the name of the old and new files, but I would not have a way to just put the new one, and another one I do not know how to leave the files with .pdf ... when I execute the code I have to put manual.
Sorry for the questions ... I do not have much contact with VBA.
I thank you very much for helping me.
Sub RenameFiles()
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
Sub ListFiles()
Dim MyFolder As String
Dim MyFile As String
Dim j As Integer
MyFolder = "C:\Users\AnaWill\Desktop\Holerites Folha\Nova pasta"
MyFile = Dir(MyFolder & "\*.*")
a = 0
Do While MyFile <> ""
a = a + 1
Cells(a, 2).Value = MyFile
MyFile = Dir
Loop
End Sub