Solved Save as to prompt for location but use filename from cell

November 16, 2018 at 05:18:48
Specs: Windows 7
I got this code from a forum and it works but I need to tweak it to show me the "save as" box but I with the name already populated with my variable FName.

Can someone help me with this?

Sub Save_New()
Dim FName As String
Dim FPath As String
'FPath = "C:"
FName = Sheets("Sheet1").Range("A1").Text
ThisWorkbook.SaveAs Filename:=FName
End Sub


See More: Save as to prompt for location but use filename from cell

Reply ↓  Report •

#1
November 16, 2018 at 06:58:37
✔ Best Answer
Got the answer from StackOverflow forum for other users:
Sub Save_New()
    Dim FName As String
    FName = Sheets("Sheet1").Range("A1").Text

    Dim DialogResult As Variant 'variant is needed because the dialog returns FALSE if users presses cancel.
    DialogResult = Application.GetSaveAsFilename(InitialFilename:=FName)

    If Not DialogResult = False Then
        ThisWorkbook.SaveAs Filename:=DialogResult
    Else
        'user clicked cancel
    End If
End Sub


Reply ↓  Report •
Related Solutions


Ask Question