Problme with using the same vba on mac

shahdelsol

Active Member
Joined
Jul 21, 2009
Messages
276
Office Version
  1. 365
Platform
  1. Windows
I am using this code on windows and working without any problme but when I use it on Mac. The code stops with error at this line:
.SaveAs FileName:=FPath & "\" & FName, FileFormat:=51

Can anyone help please

VBA Code:
Sub SaveContactXcel()
Dim FName As String
Dim FPath As String
 
FPath = "/Users/abc/Desktop/books/"
FName = Sheets("sheet1").Range("J1").Text & " " & Sheets("sheet1").Range("C10").Text

If (Len(Range("C10")) < 3) Then
MsgBox "You must have at least first name in cell C10 before saving"

Exit Sub

Else
 Application.DisplayAlerts = False
 
     'copy all sheets into new workbook
   
  ActiveWorkbook.Sheets.Copy
   Set wb = ActiveWorkbook
 
 
ActiveWorkbook.Sheets.Copy
   Set wb = ActiveWorkbook

 
   With wb
      On Error Resume Next
         .Sheets("Sheet1").Shapes("Save").Delete
         .Sheets("Sheet1").Range("J2:K2").Select
         Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
     
       
      On Error GoTo 0
   
    .SaveAs FileName:=FPath & "\" & FName, FileFormat:=51
   .Close SaveChanges:=True
   End With
     

    Application.DisplayAlerts = True
    Application.Quit
    MsgBox "The Contract Has Been Saved Successfully!"
    Set wb = Nothing

     End If
 
End Sub
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
.SaveAs FileName:=FPath & Application.PathSeparator & FName, FileFormat:=51

Try like this
 
Upvote 0
.SaveAs FileName:=FPath & Application.PathSeparator & FName, FileFormat:=51

Try like this
This worked perfectly. Thank you so much. One more question. When I try to open the saved file (file format=51), it says the file extension doesn't exist and gives option of open anyway. After I try to open it askes to update and then it opens eventaully. Did you happen to know why it does it that way? Is fileformat 51 right format for .xlsx for mac?
 
Upvote 0
You are welcome, better to include the extension.
.SaveAs (FPath & Application.PathSeparator & FName & ".xlsx")
 
Upvote 0

Forum statistics

Threads
1,214,801
Messages
6,121,644
Members
449,045
Latest member
Marcus05

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