In order to help speed up the process of saving audit sheets there is a naming convention and that has been taken care of in a reference sheet within the workbook that has a cell Defined Name
of savefile_name
.
However the audit sheets are saved on a variety of computers in the field and are eventually migrated by each user into the archive once they return to the office. Therefore I would like my macro to open the Save As
dialog, populate the name and select the .xlsm
or xlOpenXMLWorkbookMacroEnabled
(Excel Macro-Enabled Workbook) format without fail.
My current code, inspired by this post, will happily open the Save As
dialog, and populate the name, but it will not select the .xlsm
format; it always has the last format selected as when the the Save As
dialog was last opened. How to I stop this from happening?
My VBA code:
Dim FileName As String
FileName = Range("savefile_name").Value
Dim fPth As Object
Set fPth = Application.FileDialog(msoFileDialogSaveAs)
With fPth
.InitialFileName = FileName & ".xlsm"
.Title = "Save your File"
.InitialView = msoFileDialogViewList
If .Show <> 0 Then
ThisWorkbook.SaveAs FileName:=.SelectedItems(1), FileFormat:=xlOpenXMLWorkbookMacroEnabled
End If
End With