tombrown65
New Member
- Joined
- Jun 9, 2021
- Messages
- 11
- Office Version
- 365
- Platform
- Windows
I have some clunky code that I put together that includes saving an open excel workbook under a different name.
When I first set it up the GetSaveAsFilename part always put me into the Documents folder, by default. So I added the part to add the current pathname into the InitialFileName.
Prior to this change, the InitFileName variable was just set to "Output Report dd-mmm-yyy", and, if that file existed, I got a prompt warning me before saving it.
However when I made the changes the warning prompt stopped coming, and now this just overwrites any existing file with the name "Output Report dd-mmm-yyy"
How can I get that check & warning back in, and why did it disappear?
When I first set it up the GetSaveAsFilename part always put me into the Documents folder, by default. So I added the part to add the current pathname into the InitialFileName.
Prior to this change, the InitFileName variable was just set to "Output Report dd-mmm-yyy", and, if that file existed, I got a prompt warning me before saving it.
However when I made the changes the warning prompt stopped coming, and now this just overwrites any existing file with the name "Output Report dd-mmm-yyy"
How can I get that check & warning back in, and why did it disappear?
VBA Code:
'Find current folder path
currentPathName = Application.ActiveWorkbook.Path
'Create a default filename in current folder with today's date in title
InitFileName = currentPathName & "\" & "Output Report " & Format(Now, "dd-mmm-yyyy") & ".xlsm"
'Prompt for file name (allow overwriting of defualt)
Do
fileSaveName = Application.GetSaveAsFilename(InitialFileName:=InitFileName, _
filefilter:="Excel Macro Enabled Workbook (*.xlsm), *.xlsm)", Title:="Specify Output File Name for Report")
Loop Until fileSaveName <> False
'Save file under new filename
ThisWorkbook.SaveAs Filename:=fileSaveName, FileFormat:=xlOpenXMLWorkbookMacroEnabled