title: SaveAs function works on Microsoft PC but not on MAC
body: <p>I have VBA code that controls the user from saving the file in any other format than .xls, .xlsm or .pdf. This is to prevent the stripping out of macros during the save process.</p>
  
  <p>I have inserted a line to check if the operating system is OSx (... Like "<em>Mac</em>") which works in other macros but not this one. The process fails with "Can;t find the file object or library" with 'msoFileDialogSaveAs' highlighted.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>    Option Explicit
      Option Compare Text
  
      Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, _
          Cancel As Boolean)
  
        Dim fso As Object 'FileSystemObject
        Dim PdfSave As Boolean
        Dim SheetName As String
        If Not Application.OperatingSystem Like "*Mac*" Then
        SheetName = ActiveSheet.Name
        'Save-As action?
        If SaveAsUI Then
          Set fso = CreateObject("Scripting.FileSystemObject")
          'Abort excel's dialog
          Cancel = True
          'Create our own
          With Application.FileDialog(msoFileDialogSaveAs)
            'Select the XLSM filter by default
            .FilterIndex = 2
      Again:
            'Ok clicked?
            If .Show = -1 Then
              'Which extension should we save?
              Select Case fso.GetExtensionName(.SelectedItems(1))
                Case "xlsm"
                  'Okay
                Case "xls"
                  'Okay
                Case "pdf"
                  PdfSave = True
                  'Okay
                Case Else
                  MsgBox "Invalid file type selected!" _
                    &amp; vbCr &amp; vbCr &amp; "Only the following file formats are   permitted:" _
                    &amp; vbCr &amp; "   1. Excel Macro-Enabled Workbook (*.xlsm)" _
                    &amp; vbCr &amp; "   2. Excel 97-2003 Workbook (*.xls)" _
                    &amp; vbCr &amp; "   3. PDF (*.pdf)" _
                    &amp; vbCr &amp; vbCr &amp; "Please try again." _
                    &amp; vbCr &amp; vbCr &amp; "NOTE: 'Excel 97-2003 Workbook (*.xls)' format should be used for" _
                    &amp; vbCr &amp; "backwards compatability only!", vbOKOnly + vbCritical
                  GoTo Again
              End Select
              'Prevent that we call ourself
              Application.EnableEvents = False
              'Save the file
              If PdfSave = True Then
                  ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF,   Filename:=ActiveWorkbook.Path &amp; "\" &amp; SheetName &amp; ".pdf",  Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True
              Else
                  ThisWorkbook.SaveAs .SelectedItems(1)
              End If
              Application.EnableEvents = True
            End If
          End With
        End If
        End If
      End Sub
  </code></pre>
  
  <p>Can anyone suggest changes so that this code works for Office on both PC and MAC, or have different code that achieves the same thing.</p>
  
  <p>Thanks</p>
  
  <p>Mike</p>