Paste this code and have it call
RenameFilesInDir
it will prompt for a file to choose, (you MUST ADD REFERENCE : Microsoft Office 11.0 Object Library)
then it scans the folder and rename all files by putting the word NEW in front of the old file name.
This can be changed to any word. (at ScanFolder "New", vRetval )
Code:
Public Sub RenameFilesInDir()
Dim vDir, vRetval, vFile
'pick a file in a folder
vRetval = UserPick1File("*", vDir)
'if picked , scan all files in it
If vRetval <> "" Then
ScanFolder "New", vRetval
End If
End Sub
' pick any file in a folder to RENAME ALL files in folder
Public Function ScanFolder(ByVal pvNewWord, ByVal pvStartFile, Optional pvPattern)
Dim i As Integer, sDir As String
Dim fso, oFolder, oFile
'get the folder name
i = InStrRev(pvStartFile, "\") 'not available in '97
If i > 0 Then vDir = Left(pvStartFile, i)
'create folder object
Set fso = CreateObject("Scripting.FileSystemObject")
Set oFolder = fso.GetFolder(vDir)
'scan all files
For Each oFile In oFolder.Files
'If instr(oFile.Name , pvPattern)>0 Then
vOld = vDir & oFile.Name
vnew = vDir & pvNewWord & vOld
'MsgBox vOld & vbCrLf & vnew
Name vOld As vName
'End If
Next
Set oFile = Nothing
Set oFolder = Nothing
Set fso = Nothing
End Function
'open file dialog box
Public Function UserPick1File(ByVal pvFilter, Optional pvPath)
Dim strTable As String
Dim strFilePath As String
Dim sDialog As String, sDecr As String, sExt As String
With Application.FileDialog(msoFileDialogFilePicker) 'you MUST ADD REFERENCE : Microsoft Office 11.0 Object Library)
.AllowMultiSelect = False
.Title = "Locate a file to Import"
.ButtonName = "Import"
.Filters.Clear
.Filters.Add "All Files", "*.*"
.InitialFileName = "c:\"
.InitialView = msoFileDialogViewList 'msoFileDialogViewThumbnail
If .Show = 0 Then
'There is a problem
Exit Function
End If
'Save the first file selected
UserPick1File = Trim(.SelectedItems(1))
End With
End Function