Save Multiple Files to One Location with Dialogue Box

jordancollins

New Member
Joined
Jul 29, 2022
Messages
3
Hello, I am trying to save multiple worksheets within one file to the same file location without having to pick the folder for every file that is being saved. The file that I am currently working in has 20 sheets that get saved. I am sure that I am missing something silly...

Sub SplitEachWorksheet()
Dim FilePath As String
Dim Fldr As String
FPath = Application.ActiveWorkbook.Path
Application.ScreenUpdating = False
Application.DisplayAlerts = False
For Each ws In ThisWorkbook.Sheets
If Not ws.Name Like "Summary" Then
ws.Copy
With Application.FileDialog(4)
.AllowMultiSelect = False
If .Show <> -1 Then Exit Sub
Fldr = .SelectedItems(1)
End With
ActiveWorkbook.SaveAs Fldr & "\" & ws.Name & ".xlsx"
Application.ActiveWorkbook.Close False
Else
End If
Next ws
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Are you expecting to have an additional 20 workbooks, each having one worksheet from the source workbook?
 
Upvote 0
Move the Application.FileDialog(4) above the loop, like this:
VBA Code:
Public Sub Save_Each_Sheet_As_Workbook()

    Dim folder As Variant
    Dim ws As Worksheet
    
    With Application.FileDialog(msoFileDialogFolderPicker)
        .AllowMultiSelect = False
        .Title = "Select destination folder"
        If Not .Show Then Exit Sub
        folder = .SelectedItems(1) & "\"
    End With
    
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False  'suppress warning if .xlsx file already exists - file is replaced
    
    With ThisWorkbook
        For Each ws In .Worksheets
            If StrComp(ws.Name, "Summary", vbTextCompare) <> 0 Then
                ws.Copy
                ActiveWorkbook.SaveAs folder & ws.Name & ".xlsx"
                ActiveWorkbook.Close SaveChanges:=False
            End If
        Next
    End With
    
    Application.DisplayAlerts = True
    Application.ScreenUpdating = True
    
    MsgBox "Done"
    
End Sub
 
Upvote 0
Move the Application.FileDialog(4) above the loop, like this:
VBA Code:
Public Sub Save_Each_Sheet_As_Workbook()

    Dim folder As Variant
    Dim ws As Worksheet
   
    With Application.FileDialog(msoFileDialogFolderPicker)
        .AllowMultiSelect = False
        .Title = "Select destination folder"
        If Not .Show Then Exit Sub
        folder = .SelectedItems(1) & "\"
    End With
   
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False  'suppress warning if .xlsx file already exists - file is replaced
   
    With ThisWorkbook
        For Each ws In .Worksheets
            If StrComp(ws.Name, "Summary", vbTextCompare) <> 0 Then
                ws.Copy
                ActiveWorkbook.SaveAs folder & ws.Name & ".xlsx"
                ActiveWorkbook.Close SaveChanges:=False
            End If
        Next
    End With
   
    Application.DisplayAlerts = True
    Application.ScreenUpdating = True
   
    MsgBox "Done"
   
End Sub

@John_w that worked, thank you very much!
 
Upvote 0

Forum statistics

Threads
1,224,816
Messages
6,181,138
Members
453,021
Latest member
Justyna P

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