title: Excel VBA force save as .xlsm
body: <p>I am have limited experience in coding in VBA and have implemented some code into an excel workbook, for which I take no credit for and which I obtained via the web, so all credit to the original creator. The code forces the user to save the workbook as .xlsm. The code works fine, as shown, with a small niggle.</p>
  <pre><code>Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
  Dim FileNameVal As String
  If SaveAsUI Then
      FileNameVal = Application.GetSaveAsFilename(, &quot;Excel Macro-Enabled Workbook (*.xlsm), *.xlsm&quot;)
      MsgBox (FileNameVal)
      Cancel = True
      If FileNameVal = CStr(False) Then 'User pressed cancel
          Exit Sub
      End If
      Application.EnableEvents = False
          If Right(ThisWorkbook.Name, 5) &lt;&gt; &quot;.xlsm&quot; Then
              ThisWorkbook.SaveAs Filename:=FileNameVal &amp; &quot;.xlsm&quot;, FileFormat:=xlOpenXMLWorkbookMacroEnabled
          Else
              ThisWorkbook.SaveAs Filename:=FileNameVal, FileFormat:=xlOpenXMLWorkbookMacroEnabled
          End If
      Application.EnableEvents = True
  End If
  End Sub
  </code></pre>
  <p>The niggle is that in selecting File/SaveAs, the UI presents the SaveAs dialogue box in which I type the new filename. This then creates a further SaveAs dialogue box with input for the filename again, but the inserted filename is the original current filename not the new one entered in the previous step. It seems the new entry is not carried over to the following dialogue box. Not a big issue, just more of a niggle. Is there any way to correct this please?</p>
  <p>I had the same need with a Word Document which needed to be forced to save as a .docm. This was achieved in a different manner and all credit goes to David Zemens as answered in this post <a href="https://stackoverflow.com/questions/41514072/word-vba-force-save-as-docm/41514929#41514929">Word VBA force save as .docm</a>. This works really well for my need. I was wondering if this type of method could be used in Excel and if so what would need to change?</p>
  <p>Any help would be appreciated, thanks in advance.</p>
  <p>zump</p>