I have been trying to find a way to set up the default save options for a specific excel spreadsheet where a default file location is opened, a suggested file name appears in the dialog box and the default file type is a macro enabled workbook(*.xlsm).
I have complied the following two solutions from research; however, both seem to give me a problem where three save dialog boxes open after each other.
Specifically, when the save button is clicked, the save dialog box opens in the correct location (“My Documents/exceltests”) and with the correct file name (“AAAA”). I then click the save button which prompts another save dialog box to open with the exact same properties. After I click save on this dialog box, the workbook is saved in the correct location. However, a third dialog box also opens back in the default location of “My Documents”.
Code Sample 1
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, _
Cancel As Boolean)
With Application.FileDialog(msoFileDialogSaveAs)
.InitialFileName = "C:\My Documents\exceltests\AAAA"
.FilterIndex = 2
If .Show Then
ActiveWorkbook.SaveAs Filename:=.SelectedItems(1), _
FileFormat:=xlOpenXMLWorkbookMacroEnabled
End If
End With
End Sub
Code Sample 2
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, _
Cancel As Boolean)
End Sub
Dim fn
fn = Application.GetSaveAsFilename(InitialFileName:="C:\My Documents\exceltests\AAAA", _
fileFilter:=" Excel Macro Enabled Workbook (*.xlsm), *.xlsm,")
If fn <> False Then
ActiveWorkbook.SaveAs Filename:=fn, _
FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
End If
If anyone has any clues as to why this is happening and/or how it can be fixed I would be very grateful.