I want to change this code from inputting a name file to choosing a certain name file to save

zone709

Well-known Member
Joined
Mar 1, 2016
Messages
2,125
Office Version
  1. 365
Platform
  1. Windows
Code:
Sub SaveFileButton()
Dim SaveName As String
Const MyPath As String = "E:\"   'This is the path it's using for saves before the dates
ReName:
On Error GoTo ErrorHandle


    SaveName = Trim(InputBox("Enter file name. (blank to skip)", "Input required."))
    If Len(SaveName) > 0 Then
        SaveName = SaveName & ".xlsx"
        If Len(Dir(MyPath & Format(Now, "yy") & "-" & Format$(Now, "mmm"), vbDirectory)) = 0 Then
            MkDir MyPath & Format(Now, "yy") & "-" & Format$(Now, "mmm") & "\"
        End If
        If Len(Dir(MyPath & Format(Now, "yy") & "-" & Format$(Now, "mmm") & "\" & Format(Now, "mm") & "-" & Format(Now, "dd") & "-" & Format(Now, "yyyy"), vbDirectory)) = 0 Then
            MkDir MyPath & Format(Now, "yy") & "-" & Format$(Now, "mmm") & "\" & Format(Now, "mm") & "-" & Format(Now, "dd") & "-" & Format(Now, "yyyy") & "\"
        End If
        ActiveWorkbook.SaveAs Filename:=MyPath & Format(Now, "yy") & "-" & Format$(Now, "mmm") & "\" & Format(Now, "mm") & _
            "-" & Format(Now, "dd") & "-" & Format(Now, "yyyy") & "\" & SaveName, FileFormat:=xlOpenXMLWorkbook
    End If

Exit Sub

ErrorHandle:
    If Err.Number = 75 Then
        Resume Next
    ElseIf Err.Number = 1004 Then
        MsgBox ("That name is already used for this day.  Please try again!")
        GoTo ReName
    Else: MsgBox ("There is an unknown error")
    End If
End Sub

This will ask me to in a pop up box to name the file I want to save.

I rather have a option to select a filename to save by adding it in the code. So when the pop up box comes up it asks me which filename you like to save.

"Enter"
"Symbol"
"Restore"

etc
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Hi Frank,

To have a message with a dropdown list or option buttons you would need to create a userform...

Alternatively you could give a list of options in the Message Box and then the user could enter a number accordingly... example;

Code:
Sub SaveFileButton()
Dim SaveName As String
Const MyPath As String = "E:\"   'This is the path it's using for saves before the dates
ReName:
On Error GoTo ErrorHandle

[COLOR=#0000FF]Num = Trim(InputBox("Enter the number or name you require" & vbNewLine & "1:Enter" & vbNewLine & "2:Symbol" & vbNewLine & "3:Restore", "Input required."))

Select Case Num
    Case "1"
        SaveName = "Enter"
    Case "2"
        SaveName = "Symbol"
    Case "3"
        SaveName = "Restore"
    Case Else
        SaveName = Num
End Select[/COLOR]

If Len(SaveName) > 0 Then
    SaveName = SaveName & ".xlsx"
    If Len(Dir(MyPath & Format(Now, "yy") & "-" & Format$(Now, "mmm"), vbDirectory)) = 0 Then
        MkDir MyPath & Format(Now, "yy") & "-" & Format$(Now, "mmm") & "\"
    End If
    If Len(Dir(MyPath & Format(Now, "yy") & "-" & Format$(Now, "mmm") & "\" & Format(Now, "mm") & "-" & Format(Now, "dd") & "-" & Format(Now, "yyyy"), vbDirectory)) = 0 Then
        MkDir MyPath & Format(Now, "yy") & "-" & Format$(Now, "mmm") & "\" & Format(Now, "mm") & "-" & Format(Now, "dd") & "-" & Format(Now, "yyyy") & "\"
    End If
    ActiveWorkbook.SaveAs Filename:=MyPath & Format(Now, "yy") & "-" & Format$(Now, "mmm") & "\" & Format(Now, "mm") & _
            "-" & Format(Now, "dd") & "-" & Format(Now, "yyyy") & "\" & SaveName, FileFormat:=xlOpenXMLWorkbook
End If

Exit Sub

ErrorHandle:
    If Err.Number = 75 Then
        Resume Next
    ElseIf Err.Number = 1004 Then
        MsgBox ("That name is already used for this day.  Please try again!")
        GoTo ReName
    Else: MsgBox ("There is an unknown error")
    End If
End Sub

Cheers,
Alan.
 
Last edited:
Upvote 0
This works great learned something again thank Alan.
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,912
Members
452,366
Latest member
TePunaBloke

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