User selected save path

JimM

Well-known Member
Joined
Nov 11, 2003
Messages
741
Hi

I'm trying to write some code that will split out worksheets from my workbook and save them to a user selected directory. The directory may or may not exist at the time of running the code.
How can I get a pop window that will allow the user to navigate to\create the save directory but will not require the 'save name' as I want the macro to assign the name for the workbook

Thanks

Jim
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
try something like this
VBA Code:
Sub GetPath()
    Dim fName As String, fPath As String, newFolder, newPath As String, fullPath As String
    fName = "FileNameDeterminedByVBA.xlsm"
    fPath = GetFolder & "\"
    newFolder = InputBox("Enter name of new subfolder" & vbCr & "Leave blank to save to chosen folder" & vbCr & fPath)
    If Len(newFolder) > 0 Then
        newPath = fPath & newFolder
        On Error Resume Next
        MkDir (newPath)
        If Err.Number <> 0 Then
            MsgBox "Unable to create folder"
            GoTo Handling
        End If
        fPath = newPath & "\"
    End If
    
    fullPath = fPath & fName
    MsgBox fullPath

Handling: On Error GoTo 0

End Sub

Private Function GetFolder() As String
    Dim s As String
    With Application.FileDialog(msoFileDialogFolderPicker)
        .Title = "Select a Folder"
        .AllowMultiSelect = False
        .InitialFileName = Application.DefaultFilePath
        If .Show <> -1 Then GoTo CarryOn
        s = .SelectedItems(1)
    End With
CarryOn:
    GetFolder = s
End Function
 
Upvote 0
Thanks Yongle

Was just coming back to post that I'd found a solution but appreciate your efforts anyway

In case anyone is interested this is the code I went with

'Select output folder where output files will be saved
Set SaveDialogBox = Application.FileDialog(msoFileDialogFolderPicker)
MsgBox ("Select a TARGET folder where opened file will be saved")
If SaveDialogBox.Show = -1 Then
OutputFolder = SaveDialogBox.SelectedItems(1)
End If
 
Upvote 0

Forum statistics

Threads
1,214,382
Messages
6,119,194
Members
448,874
Latest member
Lancelots

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