• 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.

rename all the sheets of files in a folder

Marco1975

New Member
now i have almost the opposite problem to the previous thread . I should rename the sheets of all the files in a folder. all the files are closed , and all need to be renamed with the same name . for example, (to Stevie), in the folder that I posted before there were three files : pippo, pluto and paperino ; the macro should rename the sheets contained in the file for example with "mouse " . thanks.
 
In the zip file , there are two folders : a folder with the original files and another folder with the changed files . The macro should change the name of the sheets of the original files . I hope I have explained better the problem. Thanks again for the help .
 

Attachments

  • example.zip
    42 KB · Views: 5
Bit busy atm, but is this what you mean?
Code:
Sub rename()
   Dim wb As Workbook
   Dim ws As Worksheet
   Dim fd As FileDialog
   Set fd = Application.FileDialog(msoFileDialogFilePicker)
   With fd
       If .Show = -1 Then
           ForEach wb In .SelectedItems
               Set ws = wb.Worksheets(1)
                ws.Name = "mouse"
                wb.Close
           Next wb
       EndIf
   EndWith
EndSub
This will allow you to select files, then in each file, it will rename the first worksheet to "mouse"
 
Thanks Mr Stevie for this useful code
I tried it but I got object error at this line

Code:
 For Each WB In .SelectedItems


Code:
Sub RenameSheetsInWorkbooks()
  Dim WB As Workbook
  Dim WS As Worksheet
  Dim FD As FileDialog
  Set FD = Application.FileDialog(msoFileDialogFilePicker)
  With FD
      If .Show = -1 Then
          For Each WB In .SelectedItems
              Set WS = WB.Worksheets(1)
                WS.Name = "mouse"
                WB.Close (True)
          Next WB
      End If
  End With
End Sub
Thanks advanced
 
Back
Top