Rename Multiple File Names in Windows XP Professional 5.1

  • Thread starter Thread starter Chilired
  • Start date Start date
C

Chilired

I have approx 1,000 files in which the file name begins with BPM[space]unique
name.####. I would like to change all of the files to read BPM[dash].unique
name.#### without renaming each file individually. Is this possible?
 
Works with Excel 2003 and earlier - if you have Excel 2007, you need to use DIR instead of
FileSearch. Change the folder to your path, or uncomment the Thisworkbook.Path line and store the
file with the macro in the same folder as your BPM files.....

Sub RenameFiles()
Dim oldName As String
Dim newName As String
With Application.FileSearch
.NewSearch
.LookIn = "C:\Folder Name"
'.LookIn = ThisWorkbook.Path
.FileType = msoFileTypeAllFiles
.SearchSubFolders = True ' Careful with this option...
If .Execute > 0 Then
For i = 1 To .FoundFiles.Count
If .FoundFiles(i) Like "*\BPM *" Then
newName = Replace(.FoundFiles(i), "\BPM ", "\BPM-")
oldName = .FoundFiles(i)
Name oldName As newName
End If
Next i
End If
End With
End Sub


HTH,
Bernie
MS Excel MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top