SaveAs Not Working on a Mac

masouder

Board Regular
Joined
Jul 5, 2013
Messages
118
Office Version
  1. 2013
Platform
  1. Windows
I built a model that needs to run on a PC and on a Mac. One of the routines copies a sheet from the model to a new workbook and saves the new workbook. The following code runs fine on a PC, but the line that saves the file throws a "Method 'SaveAs' of Object" error on a Mac (last line). Does anyone know what I have to do get it work on a Mac?

VBA Code:
NewFileName = ThisWorkbook.Path & "\" & Format(Now, "yyyy.mm.dd") & "_" & "Invoice Payments_" & [SetupProjectName] & ".xlsx"
Set NewBook = Workbooks.Add
shtInvoicePayments.Copy Before:=NewBook.Sheets(1)
NewBook.SaveAs FileName:=NewFileName

Thank you!
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Try (untested, please note we might need the Mac version)..
VBA Code:
    NewFileName = ThisWorkbook.Path & Application.PathSeparator & Format(Now, "yyyy.mm.dd") & "_" & "Invoice Payments_" & [SetupProjectName] & ".xlsx"
    Set NewBook = Workbooks.Add
    shtInvoicePayments.Copy Before:=NewBook.Sheets(1)
    NewBook.SaveAs Filename:=NewFileName, FileFormat:=51
 
Upvote 0
Thanks for the quick reply. Unfortunately, I still get the same error.
 
Upvote 0
Change the 51 to 52 but we will need to amend the code if that works
 
Upvote 0
Unfortunately, that didn't work either. I developed an acceptable workaround, so I think I'm good. Appreciate your help.
 
Upvote 0
Happy you have found a workaround (just as a btw you were testing the 52 on the Mac and not the PC?)
 
Upvote 0

Forum statistics

Threads
1,224,602
Messages
6,179,839
Members
452,948
Latest member
UsmanAli786

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