Excel VBA - GetSaveAsFileName

Rolandos

New Member
Joined
Oct 11, 2018
Messages
7
Good Morning, Trying "in vain" to show the original file name in the "file name:" dialog box. Can anyone help?
================================
Sub RGH_SaveAs()


Dim FName

thisfilename = ActiveWorkbook.Name

thisfilenameinquotes = Chr(34) & thisfilename & Chr(34)


IniName = thisfilenameinquotes & Format(Now, "yyyy_mm_dd")




FName = Application.GetSaveAsFileName(InitialFileName:=IniName, FileFilter:="Excel Files (*.xlsx), *.xlsx", Title:="RGH Save As")

If FName = False Then Exit Sub
ActiveWorkbook.SaveAs FileName:=FName, FileFormat:=51


End Sub
===============
thanks in advance
Roland
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
THis is how I do it - (My Original Filename also resides in cell BP37)

Code:
Dim InitialName As String
Dim fileSaveName As Variant
Dim DesktopPath
DesktopPath = Application.ActiveWorkbook.Path
ChDir DesktopPath
InitialName = targetSheet.Range("BP37") & " Your Desc"
fileSaveName = Application.GetSaveAsFilename(InitialFileName:=InitialName, FileFilter:="Excel Files (*.xlsm), *.xlsm", title:="Save As")
'-----------------------------------------------
If fileSaveName <> "False" Then
    ActiveWindow.DisplayWorkbookTabs = False
    On Error Resume Next
    ThisWorkbook.saveas Filename:=fileSaveName
    On Error GoTo 0
End If
'-----------------------------------------------
ActiveWorkbook.Save
 
Upvote 0
2 things:

1 You don't need to add quotes around the filename.

2 You need to add the date before the file extension.

Try this.
Code:
Sub RGH_SaveAs()
Dim thisfilename As String
Dim IniName As String
Dim FName As Variant

    thisfilename = ActiveWorkbook.Name

    IniName = Left(thisfilename, Len(thisfilename) - 5) & Format(Now, "yyyy_mm_dd") & Right(thisfilename, 5)

    FName = Application.GetSaveAsFilename(InitialFileName:=IniName, FileFilter:="Excel Files (*.xlsx), *.xlsx", Title:="RGH Save As")

    If FName = False Then Exit Sub
    
    ActiveWorkbook.SaveAs Filename:=FName, FileFormat:=51

End Sub
 
Upvote 0
Thanks a lot.
This only worked when I remove the following from the code:" & Right(thisfilename, 5) "
 
Upvote 0
To include the file extension in the filename it would need to match the file extension you are using in the file filter of GetSaveAsFileName.

For example, if the active workbook had the extension '.xlsm' then it wouldn't work.
 
Upvote 0

Forum statistics

Threads
1,214,522
Messages
6,120,022
Members
448,939
Latest member
Leon Leenders

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