View Single Post
 
Old 06-27-2014, 10:52 AM
charlesdh charlesdh is offline Windows 7 32bit Office 2010 32bit
Expert
 
Join Date: Apr 2014
Location: Mississippi
Posts: 382
charlesdh is on a distinguished road
Default

Hi,

Take a look at this it may help.
You can make correction to it.
I was not sure about "wb".
Code:
Sub RenameAllExcelFilesInDirectory()
Dim iReply As String ''' Added
With Application.FileDialog(msoFileDialogFolderPicker)
.Show
filepath = .SelectedItems(1)
End With

Set r = Workbooks.Add.Worksheets(1).Range("A1")
StrFile = Dir(filepath & "\*.*")

Do While Len(StrFile) > 0
strExtension = Split(StrFile, ".")(UBound(Split(StrFile, ".")))

Set wb = Workbooks.Open(filepath & "\" & StrFile)
StrNewfullfilename = ThisWorkbook.Sheets(1).Range("B1").Value & "." & strExtension''' added this workbook name not sure if this is what u wanted
wb.Close

r.Value = StrFile 'print old name
r.Offset(, 1).Value = StrNewfullfilename 'print new name
Set r = r.Offset(1)
Name filepath & "\" & StrFile As filepath & "\" & StrNewfullfilename
StrFile = Dir
iReply = InputBox(Prompt:="Please Enter Next File", _
            Title:="Update File")
    If iReply = "" Then Exit Sub
    ThisWorkbook.Sheets(1).Range("B1").Value = iReply
Loop

End Sub
Reply With Quote