Unable to save as PDF from VBA in mac

橙三吉。 提交于 2019-11-27 08:14:51

问题


I am trying to save a range from a sheet as PDF through VBA. Following is the code that I have written.

Sheets("PO Format").PageSetup.PrintArea = "$B$6 : $J$42"
Sheets("PO Format").Range("B6:J42").ExportAsFixedFormat Type:=xlTypePDF, Filename:=Sheets("User Settings").Range("B15") & "/" & Sheets("PO Format").Range("F7"), Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True

The weird thing is that it is working fine on one system and I able to save it at the mentioned path and then also send out a mail, but while testing it on another system I am getting the error as "Error while printing". Completely clueless. Can anyone help??


回答1:


In Mac Office 2016 Microsoft have to deal with Apple’s sandbox requirements due to which VBA needs permission to access folders and this is not prompted while trying to save via VBA instead it gives an error. But there are a few places on Mac that one can use to let the code do what it needs to do without user interaction.

one such path is /Users/username/Library/Group Containers/UBF8T346G9.Office This folder gets created when Office 2016 is installed.

So I saved the PDF to this folder, moved it to the desired location and it is working fine now.

For more details and the code go through http://www.rondebruin.nl/mac/mac034.htm




回答2:


Make sure that Excel SaveAsPDFandXPS addin is installed, if available for Mac then you should be able to find it on Microsoft site,it available for free. Install it then the code should work just fine.



来源:https://stackoverflow.com/questions/38148305/unable-to-save-as-pdf-from-vba-in-mac

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!