Hi Hat,
I see the Weasel beat me to the punch...
This is a possible alternative. save the code below in a new workbook. The code below will locate the workbooks you want to rename then save them with the name in B2. The workbooks will be saved in the same directory as the workbook with the code below.
'Option Explicit
'32-bit API declarations
Declare Function SHGetPathFromIDList Lib "shell32.dll" _
Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long
Declare Function SHBrowseForFolder Lib "shell32.dll" _
Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As Long
Public Type BROWSEINFO
hOwner As Long
pidlRoot As Long
pszDisplayName As String
lpszTitle As String
ulFlags As Long
lpfn As Long
lParam As Long
iImage As Long
End Type
Function GetDirectory(Optional Msg) As String
Dim bInfo As BROWSEINFO
Dim path As String
Dim r As Long, x As Long, pos As Integer
' Root folder = Desktop
bInfo.pidlRoot = 0&
' Title in the dialog
If IsMissing(Msg) Then
bInfo.lpszTitle = "Select a folder."
Else
bInfo.lpszTitle = Msg
End If
' Type of directory to return
bInfo.ulFlags = &H1
' Display the dialog
x = SHBrowseForFolder(bInfo)
' Parse the result
path = Space$(512)
r = SHGetPathFromIDList(ByVal x, ByVal path)
If r Then
pos = InStr(path, Chr$(0))
GetDirectory = Left(path, pos - 1)
Else
GetDirectory = ""
End If
End Function
Sub BatchProcess()
Dim FileSpec As String
Dim i As Integer
Dim OldWbkName As String
Dim NewWbkName As String
Dim strPath As String
Application.ScreenUpdating = False
'Define directory where files are to be saved
Application.StatusBar = "Specify Directory for Saving Files..."
strPath = ThisWorkbook.path
filepath = GetDirectory(Msg)
Application.StatusBar = ""
FileSpec = "*.xls"
'Create a FileSearch object
Set fs = Application.FileSearch
With fs
.LookIn = filepath
.Filename = FileSpec
.Execute
'Exit if no files are found
If .FoundFiles.Count = 0 Then
MsgBox "No files were found. Check directory."
Exit Sub
End If
End With
'Loop through the files and process them
For i = 1 To fs.FoundFiles.Count
ChDir (filepath)
Workbooks.Open Filename:=fs.FoundFiles(i)
Application.StatusBar = "Processing " & i & " of " & fs.FoundFiles.Count & " files"
' OldWbkName = ActiveWorkbook
Application.DisplayAlerts = False
NewWbkName = Sheets(1).Range("B2")
ActiveWorkbook.SaveAs Filename:=strPath & "" & NewWbkName
ActiveWorkbook.Close
Next i
Application.DisplayAlerts = True
Application.StatusBar = ""
End Sub
Display More
HTH
Graeme:biggrin: