Adding popup to select folder for the exported csv sheets

linister

New Member
Joined
Jan 16, 2021
Messages
23
Office Version
  1. 2019
Platform
  1. Windows
Hi,

I created a button that exports all sheets to a sperate excel csv workbook, however what I want is when clicking on the button to get a popup that asks me where do i want to save those workbooks.

Here's the macro that I currently have:

VBA Code:
Sub Button1_Click()
        Dim xWs As Worksheet
        Dim xcsvFile As String
        For Each xWs In Application.ActiveWorkbook.Worksheets
            xWs.Copy
            xcsvFile = "C:\Users\linja\Desktop\" & "\" & xWs.Name & ".csv"
            Application.ActiveWorkbook.SaveAs Filename:=xcsvFile, _
            FileFormat:=xlCSV, CreateBackup:=False
            Application.ActiveWorkbook.Saved = True
            Application.ActiveWorkbook.Close
        Next
    End Sub

I don't want to write the path of where to export the xcsvFile manually, i want to get the popup that allows me to choose the export folder.

Thanks in advance!
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
How about
VBA Code:
Sub Button1_Click()
        Dim xWs As Worksheet
        Dim xcsvFile As String
        Dim Pth As String
        
      With Application.FileDialog(4)
         .AllowMultiSelect = False
         If .Show Then Pth = .SelectedItems(1)
      End With

        For Each xWs In Application.ActiveWorkbook.Worksheets
            xWs.Copy
            xcsvFile = Pth & "\" & xWs.Name & ".csv"
            Application.ActiveWorkbook.SaveAs fileName:=xcsvFile, _
            FileFormat:=xlCSV, CreateBackup:=False
            Application.ActiveWorkbook.Saved = True
            Application.ActiveWorkbook.Close
        Next
    End Sub
 
Upvote 0
Solution
Sub Button1_Click() Dim xWs As Worksheet Dim xcsvFile As String Dim Pth As String With Application.FileDialog(4) .AllowMultiSelect = False If .Show Then Pth = .SelectedItems(1) End With For Each xWs In Application.ActiveWorkbook.Worksheets xWs.Copy xcsvFile = Pth & "\" & xWs.Name & ".csv" Application.ActiveWorkbook.SaveAs fileName:=xcsvFile, _ FileFormat:=xlCSV, CreateBackup:=False Application.ActiveWorkbook.Saved = True Application.ActiveWorkbook.Close Next End Sub
Yess!!! works great!!! thanks alot Fluff you're the best
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,326
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