Save as with dialog box with pre-positioned file name

mark hansen

Well-known Member
Joined
Mar 6, 2006
Messages
534
Office Version
  1. 2016
Platform
  1. Windows
So far I have the following code that asks for a file name, adds the date after the user-entered file name and saves a xls file in the paths of the main file. It works, but I would like to get a dialog box to change the path of the saved file. It would be great if the user-entered file name and date can be pre-positioned in the file name box. What would I need to add to the code to get it to do this?

Thanks,
Mark


Code:
Private Sub CommandButton3_Click()
'===============SAVE DATA TO UPLOAD FILE================
Dim ws As Worksheet
Dim MyDay As String
Dim MyMonth As String
Dim MyYear As String
Dim MyPath As String
Dim MyFileName As String
Dim MyCellContent As String
Dim LR As Integer
Dim test
Sheets("Upload List").Select
LR = Worksheets("Upload List").Cells(Rows.count, 1).End(xlUp).Row + 1
  If LR = 2 Then
     MsgBox ("Nothing to save")
     Sheets("Opening Sheet").Select
     Exit Sub
   End If

MyDay = Day(Now)
MyMonth = Month(Now)
MyYear = Year(Now)
MyPath = ActiveWorkbook.path
MyCellContent = InputBox("Upload file name", "Upload File Name")
Set ws = ActiveSheet
MyFileName = MyCellContent & "_" & MyMonth & "." & MyDay & "." & MyYear & ".xls"
ws.Copy
ChDir MyPath

Application.DisplayAlerts = False
  ActiveWorkbook.SaveAs Filename:= _
       MyFileName, FileFormat:=xlExcel8, password:="", WriteResPassword:="", _
        ReadOnlyRecommended:=False, CreateBackup:=False
Application.DisplayAlerts = True

ActiveWorkbook.Close
Sheets("Opening sheet").Select
MsgBox ("Upload file created named: " & MyFileName)
End Sub
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,459
Messages
5,831,760
Members
430,088
Latest member
meagerd

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
Top