Saving new workbook in VBA: mac

joshman108

Active Member
Joined
Jul 6, 2016
Messages
310
Here is my simple code, found online.

Code:
Sub test2()
' copies a worksheet into a new file and saves it onto desktop
    
    Dim newWB As Workbook
    Sheets("Sheet1").Select
'Add a new workbook and copy the Members sheet over
    Set newWB = Workbooks.Add
    ThisWorkbook.Sheets("Sheet1").Copy Before:=newWB.Sheets(1)

'this saves the new workbook
    With newWB
    .SaveAs Filename:="Macintosh HD:Users:josh.flori:Desktop:TEST.xlsx", FileFormat:=xlCSV, CreateBackup:=False
    .Saved = True
    .Close
    End With

End Sub

It will succeed in opening a new workbook, pasting the data from original sheet1 and will actually name the new file "TEST". But I get hit with
Code:
Run-time error '1004':


Application-defined or object-defined error

and when I check the desktop I see that it has failed to actually save. Any ideas on why?

Thanks!
 
Last edited:

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Oh gosh, I missed that, regardless, I've changed to the following:

Code:
 .SaveAs Filename:="Macintosh HD:Users:josh.flori:Desktop:TEST.csv", FileFormat:=xlCSV, CreateBackup:=False

and still have the same results as mentioned originally.
 
Upvote 0

Forum statistics

Threads
1,215,972
Messages
6,128,026
Members
449,414
Latest member
sameri

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top