• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Using VBA , How to rename Workbooks

margil patel

New Member
I Have an example of rename worksheet. Like this example I want rename my workbooks.
any one help me?

Thanks...
 

Attachments

  • Rename Worksheet.xlsm
    18.3 KB · Views: 5
Hi Margil,
Are the workbooks that you want to rename saved in a folder?
Is that a single folder or there are subfolders as well?
 
Dear Margil

A sub routine such as this should do the trick. You will need to add the microsoft scipting runtime reference for this to work.

Sub RenameFiles()
Dim fso As New FileSystemObject
Dim flds As Files
Dim flds2 As Files
Dim FolderName As String
FP = ThisWorkbook.Path

Set flds = fso.GetFolder(FP).Files
For I = 1 To 133
oldname = Cells(I, 3).Value
newName = Cells(I, 2).Value
For Each f In flds
If f.Name = oldname Then
Workbooks.Open f
Workbooks(f.Name).SaveAs newName
Workbooks(f.Name).Close
Workbooks(newName).Close
f.Delete
End If
Next f

Next I
End Sub
 
Back
Top