VBA macro in Excel 2016 for Mac: SaveAs will not work with a CSV file format
<p>I am running a VBA macro in Excel 2016 for Mac. The macro works on Windows platforms with Excel 2016, and on Mac platforms with earlier than the 2016 version. The issue appears specific to Excel 2016 for Mac when trying to export a CSV.</p>

<p>The code is supposed to allow the user to click a button, which will then export an active worksheet to a CSV file. While a similar issue was documented here (<a href="https://stackoverflow.com/questions/28967762/getting-method-saveas-of-object-workbook-failed-error-while-trying-to-save-an">Getting &quot;method saveas of object _workbook failed&quot; error while trying to save an XLSM as CSV</a>), unfortunately while changing <code>xlCSV</code> to <code>6</code> worked for them, this has not worked for me.</p>

<p>The code works up until the <code>ActiveWorkbook.SaveAs Filename:=newFileName, FileFormat:=6, CreateBackup:=False</code> line, which then throws the error:</p>

<blockquote>
  <p>Run-time error '1004':Method 'SaveAs' of object '_Workbook' failed</p>
</blockquote>

<p>If I change <code>FileFormat</code> to <code>51</code> (.xlsx) or <code>53</code> (.xlsm) the code will successfully finish. However, if <code>FileFormat</code> is set to <code>6</code> (.csv) the code will throw the error above. I am unable to <code>SaveAs</code> <code>xlCSV</code> or <code>xlCSVMac</code>.</p>

<p>My full script is below:</p>

<pre><code>Sub btnExportCSV_Click()
Dim oldFileName As String
Dim newFileName As String
Dim timeStamp As String
Dim fileAccessGranted As Boolean
Dim filePermissionCandidates
Dim wsPath As String

timeStamp = Format(Now, "yyyymmddhhmmss")

wsPath = Application.ThisWorkbook.Path

oldFileName = ThisWorkbook.FullName
newFileName = Mid(oldFileName, 1, InStrRev(oldFileName, ".") - 1) &amp; timeStamp &amp; ".csv"

' Check if software is Office 2016 for Mac
' Documentation for this comes from https://dev.office.com/blogs/VBA-improvements-in-Office-2016
#If MAC_OFFICE_VERSION &gt;= 15 Then
    filePermissionCandidates = Array(wsPath)
    fileAccessGranted = GrantAccessToMultipleFiles(filePermissionCandidates)
#End If

Application.DisplayAlerts = False

Sheets("OfflineComments").Activate
Sheets("OfflineComments").Copy
ActiveWorkbook.SaveAs Filename:=newFileName, FileFormat:=6, CreateBackup:=False
ActiveWorkbook.Save
ActiveWindow.Close

MsgBox ("Offline comments exported to " &amp; newFileName)

Application.DisplayAlerts = True
End Sub
</code></pre>

<p>I have tried:</p>

<ul>
<li>Adding a full path to the input/output file names</li>
<li>Ensuring that version of Excel is checked for and permissions allowed by user</li>
<li>Various file types for the <code>FileFormat</code> parameter, but as mentioned, only two types actually worked.</li>
<li>Trying the code mentioned in the above-linked article, which did not help (and which is why I am posting the original code here).</li>
</ul>