Save as with dialog box with pre-positioned file name

mark hansen

Well-known Member
Joined
Mar 6, 2006
Messages
511
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
 

Some videos you may like

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).

Watch MrExcel Video

Forum statistics

Threads
1,122,837
Messages
5,598,375
Members
414,233
Latest member
WolverineNurse

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