VBA export worksheet as PDF (Mac 2016) error

梦想的初衷 提交于 2019-12-24 22:07:57

问题


I am struggling to export my worksheet as PDF.

Here is my code, FYI I am using Office 2016 for MAC

Sub saveactiveworkbook()

Dim FileName As String
Dim FolderName As String
Dim Folderstring As String
Dim FilePathName As String


ActiveSheet.PageSetup.Orientation = xlLandscape



FolderName = "TestVBA"
FileName = "DV" & ".pdf"

  Folderstring = "/Users/Vallier/Documents/Test/TestVBA"
  FilePathName = Folderstring & Application.PathSeparator & FileName

  ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, FileName:= _
  FilePathName, Quality:=xlQualityStandard, _
  IncludeDocProperties:=True, IgnorePrintAreas:=False

MsgBox FilePathName

End Sub

When I launch the program I have a warning box that says: "Run-time Error '1004':

Application-Defined or object-defined error"

I try to remedy to this by defining active sheet by "ws" upfront but I then have another error saying:

"ExportAsFormat of object_ worksheet failed"

Any ideas?

Many Thanks,


回答1:


The problem comes from Apple's sandboxing rules. You can no longer save or open directly from VBA to any folder that you want. You may only write to a folder that Excel has rights to. This probably includes exporting a PDF, although I have not tested.

Here is an excellent page by Ron de Bruin detailing how to deal with Apple's sandboxing issues in VBA.

https://www.rondebruin.nl/mac/mac034.htm



来源:https://stackoverflow.com/questions/49029182/vba-export-worksheet-as-pdf-mac-2016-error

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