How do I make a batch rename macro that batch renames files I have in a specific directory?
I have made a macro that grabs all filenames of all files of a specific folder (directory string referenced in F3) and lists them into the A column.
Now I have all renames in the column next to it.
(Eg. I want to rename “file1.file” in my directory to “newfile1.file”
I have the string “file1.file” listed in cell A1 and “newfile1.file” as listed in cell B1, same goes for the strings in A2 until A999 and B2 till B999 respectively)
Here is the macro that grabs the filenames by the way:
Sub GetFileNames
Dim oSheet As Object
Dim iCounter As Integer
Dim stFileName As String
Dim stPath As String
Doc = ThisComponent
Sheet = Doc.Sheets(0)
Cell = Sheet.getCellByPosition(5,2)
oSheet=ThisComponent.CurrentController.ActiveSheet
'Change MYPATH to the name of the directory where files are to be obtained'
'Directories within this path will not be listed'
stPath = Cell.string & GetPathSeparator()
stFileName = Dir(stPath, 0)
'This For loop clears Col A rows 2 through 999'
For iCounter = 1 to 999
'Change here if Column,Row of files is different - iCounter is Row'
oSheet.getCellByPosition(0,iCounter).String = ""
Next iCounter
iCounter = 0
Do While (stFileName <> "")
iCounter = iCounter + 1
'File names will start in Col `A` (signified by 0) Row 2 (iCounter)'
oSheet.getCellByPosition(0,iCounter).String = stFileName
stFileName = Dir()
Loop
End Sub