1
votes

I have a excel macro working on Excel on my PC, but now I tried to get it working on my new Mac with Excel 2016. Basically it saves the actual File based on a Field in the Workbook and the actual date. Then it saves the same file as pdf. When I exceute the script I get a runtime error that the file cannot be saved, pointig on the line where "SaveAs"... is located. I think this has to do with the variables in the filename, because a fixed filename is woking...

   Sub save_pdf() 
Dim nr, jahr, jahreszahl, stdPfad, Dateiname
jahreszahl = Year(Now)
stdPfad = "Users/**myname**/Dropbox/Buchhaltung & Steuer/Customer/Zeiterfassung/" & jahreszahl & "/" & Format(Now, "mmmm") & "/"
Dateiname = stdPfad & "Zeiterfassung " & " " & Format(Now, "mmmm ") & [Projekt] & " " & Format(Now, "ddmmyyyy")
ActiveWorkbook.SaveAs Filename:=Dateiname
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=Dateiname _
    & ".pdf", Quality:= _
    xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
    OpenAfterPublish:=False
End Sub

Can someone push me in the right direction?

2

2 Answers

0
votes

First of all, could you please, post here the text of the error? My first guess is that the writing permissions for that folder lead to this error. You could do something like this from the terminal:

chmod 777 Users/**myname**/Dropbox/Buchhaltung & Steuer/Customer/Zeiterfassung

Note that this command adds full permissions (Read, Write, Execute) for every user of your computer for that folder.

0
votes

Office/Excel 2016 for Mac does not appear to have access to all folders. Saving to path /Users/username/Library/Group Containers/UBF8T346G9.Office/file_name.pdf worked for me, as mentioned here by Kamlesh: Unable to save as PDF from VBA in mac