VBA to split workbooks into files only saving as "sheet1.xlsx"

ROBINSON_US

New Member
Joined
Feb 27, 2006
Messages
25
I needed a quick fix to break out my worksheet tabs into separate files, so I found the code below. However, when it runs, it doesn't break anything out, it just saves one worksheet as "sheet1.xlsx". Here's the code that another user was kind enough to provide:
(it came from: Copying/Saving Worksheets from a large workbook into separate files). I'm running Office 2016. Does anyone have any ideas as to why this wouldn't work, or is there a way to specify a specific folder to save the files? The feedback from other users would indicate that it's working great for them; I'm wondering if I have some issue with Excel itself... Thanks for your input.

Sub Splitbook()

Dim xPath As String
xPath = Application.ActiveWorkbook.path
Application.ScreenUpdating = False
Application.DisplayAlerts = False
For Each xWs In ThisWorkbook.Sheets
xWs.Copy
Application.ActiveWorkbook.SaveAs Filename:=xPath & "" & xWs.Name & ".xlsx"
Application.ActiveWorkbook.Close False
Next
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
This works for me, try:
Code:
Sub SplitBook_v1()

    Dim str As String
    Dim wks As Worksheet
    Dim wkb As Workbook
    
    str = Replace("@2\@1.xlsx", "@2", ThisWorkbook.path)
    Debug.Print str
    
    With Application
        .ScreenUpdating = False
        .DisplayAlerts = False
    End With
    
    For Each wks In ThisWorkbook.Sheets
        wks.Copy
        Set wkb = ActiveWorkbook
        With wkb
            .SaveAs Replace(str, "@1", wks.Name)
            .Close False
        End With
        Set wkb = Nothing
    Next wks
    
    With Application
        .ScreenUpdating = True
        .DisplayAlerts = True
    End With
    
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top