title: vba - saving file to my personal desktop code
body: <p>I have the following code which is designed so I can quick save to my desktop and then put the file into a folder. This code works fine if the file is already saved in an .xls, .csv, .xlsx or .xlsm file extension, however, when the file IS NOT saved, I only get the pop-up message boxes, and nothing happens. I was thinking about re-structuring using a CASE STATEMENT with right(activeworkbook.name, 4), but didn't know how to structure as I am not familiar with these statements.  Thank you.</p>
  
  <pre><code>Sub SavetoDesktop()
  
  'this macro will save the activesheet into the default path giving it the current name and xlsx extension
  
      Dim fname As String
  
  '    If Right(ActiveWorkbook.Name, 5) &lt;&gt; ".xlsx" And Right(ActiveWorkbook.Name, 5) &lt;&gt; ".xls" And _
  '    Right(ActiveWorkbook.Name, 5) &lt;&gt; ".xlsm" And Right(ActiveWorkbook.Name, 5) &lt;&gt; ".csv" Then
  
                   If Right(ActiveWorkbook.Name, 5) = ".xlsx" Then
                           fname = Application.DefaultFilePath &amp; "\" &amp; Application.WorksheetFunction.Substitute(ActiveWorkbook.Name, ".xlsx", "") &amp; ".xlsx"
                           ActiveWorkbook.SaveAs Filename:=fname
                   Else
                       MsgBox "Not an .xlsx file!"
                       ActiveWorkbook.SaveAs Filename:="C:\Users\mmirabelli\Desktop\" &amp; ActiveWorkbook.Name &amp; ".xlsx"
                   End If
  
                   If Right(ActiveWorkbook.Name, 4) = ".csv" Then
                           fname = Application.DefaultFilePath &amp; "\" &amp; Application.WorksheetFunction.Substitute(ActiveWorkbook.Name, ".csv", "") &amp; ".csv"
                           ActiveWorkbook.SaveAs Filename:=fname
                   Else
                       MsgBox "Not an .csv file!"
                       MsgBox ActiveWorkbook.Name
  
                   End If
  
                   If Right(ActiveWorkbook.Name, 4) = ".xls" Then
                           fname = Application.DefaultFilePath &amp; "\" &amp; Application.WorksheetFunction.Substitute(ActiveWorkbook.Name, ".xls", "") &amp; ".xls"
                           ActiveWorkbook.SaveAs Filename:=fname
                    Else
                       MsgBox "Not an .xls file!"
                    End If
  
                   If Right(ActiveWorkbook.Name, 5) = ".xlsm" Then
                           fname = Application.DefaultFilePath &amp; "\" &amp; Application.WorksheetFunction.Substitute(ActiveWorkbook.Name, ".xlsm", "") &amp; ".xlsm"
                           ActiveWorkbook.SaveAs Filename:=fname
                   Else
                      MsgBox "Not an .xlsm file!"
                   End If
  
  '     Else
  '
  '     ActiveWorkbook.SaveAs Filename:="C:\Users\mmirabelli\Desktop\" &amp; ActiveWorkbook.Name &amp; ".xlsx"
  
  '     End If
  
  
  'MsgBox Application.DefaultFilePath
  'MsgBox ActiveWorkbook.Name
  '
  '    ActiveWorkbook.SaveAs Filename:=fname
  '
  End Sub
  </code></pre>