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

macro that saves all the sheets individually with their own names

Marco1975

New Member
hi, I would like to make a macro that saves all the sheets individually with their own names . I enclose the original file and a folder with the result that I would get . I would like to specify that I don't want to manually enter in the macro sheet names , but I would like that the macro them it extracted directly from the file . Thank you.
 

Attachments

  • example.zip
    63.6 KB · Views: 1
Hi Marco
So, either you're trolling, or just very unlucky with spaces. XD
your subfolder 'final results' has 2 spaces in the name, and 2 of the 3 filenames in your list on the tab 'home' have spaces after them.
If you rename your folder to have one space, then this should do what you are asking:

Code:
Sub savesheet()
    Dim wb As Workbook
    Dim sheetnum As Integer, numsheets As Integer
    Dim sheetname As String, path As String, wbpath As String
    path = ActiveWorkbook.path
    sheetnum = 2
    numsheets = Application.WorksheetFunction.CountA(Sheets("home").Range("A1:A50"))
    While sheetnum < numsheets + 1
        sheetname = Sheets("home").Range("A" & sheetnum).Text
        sheetname = Trim(sheetname)
        Sheets(sheetname).Copy
        ActiveWorkbook.SaveAs path & "\final results\" & sheetname & ".xlsx"
        Workbooks("original file.xlsm").Activate
        sheetnum = sheetnum + 1
    Wend
End Sub

I added a trim to remove spaces from the strings in column A of the 'home' tab.
Let me know how it goes for you.
 
Great!!!! Steve i'm Italian excuse me for my English , I use google translate so there are certainly big mistakes in what I wrote . However, you understand very well the problem . Thanks for the solution. :)
 
No problem, your English is great.
Watch out for spaces at the end of strings!! (and double spaces within them)
 
Back
Top