VBA Code to save with a user specified directory and file name

Joven76

New Member
Joined
Oct 10, 2017
Messages
7
So what I'm wanting to to may be rather simple, but I'm having a difficult time finding the answer. I have a file of tracking numbers that is client specific. What I want to do is create a macro where the user will specify the client name and a file directory, and the macro uses this information to save the file in the directory with the specified client name and date.

What I'd like to do is have the macro pull up the saveas window, but already have the name generated, so all the user has to do is specify the file destination. How do I go about doing this?
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Try:
Code:
Sub SaveFile()
    Dim fName As String
    Dim sPath As String
    fName = InputBox("Enter a client name.")
    If fName = "" Then Exit Sub
    With Application.FileDialog(msoFileDialogFolderPicker)
        .AllowMultiSelect = False
        .Show
        If .SelectedItems.Count > 0 Then
            sPath = .SelectedItems(1)
            Application.DisplayAlerts = False
            ActiveWorkbook.SaveAs Filename:=sPath & Application.PathSeparator & fName & Replace(Date, "/", "-"), FileFormat:=51
            Application.DisplayAlerts = True
            MsgBox ("The file has been saved with the name: " & fName)
        End If
    End With
End Sub
 
Upvote 0
Thanks mumps, it worked with one exception.

The code
Code:
[COLOR=#333333] MsgBox ("The file has been saved with the name: " & fName)[/COLOR]
only shows the fName that I input from the input box, not the whole file name with the date. How do I fix that?
 
Upvote 0
Replace that line of code with this one:
Code:
MsgBox ("The file has been saved with the name: " & fName & Replace(Date, "/", "-"))
 
Upvote 0

Forum statistics

Threads
1,223,898
Messages
6,175,274
Members
452,628
Latest member
dd2

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