0
Boa Tarde Comunidade,
I am 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... Like to get the PDF in the folder then rename them as my spreadsheet someone knows how to do this I did several searches and so far I got nothing.
Thanks for the help
It is a little tense the practice of language change since I study Java and started doing VBA. I did what I knew, but I got enough data from google searches.
In my code, I’m having to inform the name of the old and new file, but I wouldn’t have a way to just put the new one, and another I don’t know how to leave the files with .pdf... when I run the code I have to put manual.
Sorry for the questions... I don’t have much contact with VBA.
Thank you so 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
Ideal to put what you already tried to do in vba... but I can give you a light... try to search for a amacro to list files from a folder and when listing you can change the name of the file. Here’s a template... http://spreadsheetpage.com/index.php/file/mp3_file_lister/ when you have access to a pc I can help you with the code.
– Evert
All right, I’m tweaking your code to run as it should, but I was wondering... will it always be 125 files? i.e., should the names be exactly 125 names in column "B" (B1:B125)? The "old" names in the files doesn’t matter? Nor the order?
– Evert