Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #3  
Old 06-27-2014, 10:52 AM
charlesdh charlesdh is offline Can anyone here tweek this macro for renaming Excel files based on a cell's contents? Windows 7 32bit Can anyone here tweek this macro for renaming Excel files based on a cell's contents? 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
 

Tags
batch rename, filename



Similar Threads
Thread Thread Starter Forum Replies Last Post
Can a macro rename Excel files based on a cellname? chrisd2000 Excel Programming 1 06-23-2014 06:50 PM
Can anyone here tweek this macro for renaming Excel files based on a cell's contents? Excel 2007, highlight entire row based on data found in one cell MSofficeBLUE Excel 2 10-15-2013 09:51 PM
Image Renaming Macro? jammer PowerPoint 5 07-15-2013 09:21 AM
Change formula cell range based on cell value Scoth Excel 4 10-25-2012 07:51 AM
Macro based on cell value ubns Excel Programming 1 05-07-2012 04:03 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:17 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft