Excel - "Runtime error '1004' Method 'SaveAs' of Object' _'workbook' Failed" Macbook

Viewed 529

Trying to save a sheet as .csv on my desktop via a makro

i keep getting the "Runtime error '1004' Method 'SaveAs' of Object' _'workbook' Failed"

Sub Export()

Dim wb As Workbook
Dim sht5 As Worksheet
Dim r As Long
Dim LastRow As Long
   
Set sht5 = ThisWorkbook.Worksheets("ExportCsv")               'Sheet to export as CSV
Set wb = Application.Workbooks.Add
    
sht5.Copy Before:=wb.Worksheets(wb.Worksheets.Count)

LastRow = Cells(Rows.Count, "A").End(xlUp).Row

For r = LastRow To 1 Step -1

If Cells(r, 10) = 0 Then

Rows(r).Delete

End If
        
Next r

Application.DisplayAlerts = False                             'Possibly overwrite without asking
wb.SaveAs Filename:="/Users/thomasduus/Desktop/1.csv", FileFormat:=xlCSV, CreateBackup:=False

Application.DisplayAlerts = True
wb.Close SaveChanges:=False
End Sub
2 Answers

I believe the mac file location works something like:

Wb.SaveAs "Macintosh HD:Users:thomasduus:Desktop:1.csv"

Your file path is incorrect, possibly the drive is C: so add C: in front and use backslashes. Corrected line:

wb.SaveAs Filename:="C:\Users\thomasduus\Desktop\1.csv", FileFormat:=xlCSV, CreateBackup:=False
Related