kelly mort
Well-known Member
- Joined
- Apr 10, 2017
- Messages
- 2,169
- Office Version
- 2016
- Platform
- Windows
Code:
Sub SaveFileCode
ChDrive ThisWorkbook.Path
ChDir ThisWorkbook.Path
DefName = "My File" & Year(Date)
FileSaveAs = Application.GetSaveAsFilename(InitialFileName:=DefName, FileFilter:="Exel Files (*.xlsm),*.xlsm",Title:="Add Name")
If FileSaveAs = False Then
MsgBox "Operation terminated"
Else
Application.EnableEvents=False
ThisWorkbook.SaveAs FileName:=FileSaveAs, FileFormat:=52, Password:="", writerespassword:="", ReadOnlyRecommended:=False
Application.EnableEvents=True
End Sub
I am using this code to save a copy of my workbook.
What I want to do next is to be able to get the filename ONLY displayed in a message box.
I was using the Dir(FileSaveAs) which kept returning blank until I noticed that the Dir function only works fine if the file is available. And in my case, the file will not exist.
I also tried
Code:
Right (FileSaveAs, InstrRev(FileSaveAs, "\")-1)
It was not able to get me only the filename.
Can someone show me the best way to get to the filename only?