VBA将工作表导出为PDF(Mac 2016)错误 [英] VBA export worksheet as PDF (Mac 2016) error

查看:252
本文介绍了VBA将工作表导出为PDF(Mac 2016)错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力将工作表导出为PDF.

I am struggling to export my worksheet as PDF.

这是我的代码,仅供参考,我正在使用Office 2016 for MAC

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

启动程序时,我会看到一个警告框: 运行时错误'1004':

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

应用程序定义的错误或对象定义的错误"

Application-Defined or object-defined error"

我尝试通过先通过"ws"定义活动工作表来对此进行补救,但是随后我又遇到另一个错误:

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

"object_工作表的ExportAsFormat失败"

"ExportAsFormat of object_ worksheet failed"

有什么想法吗?

非常感谢,

推荐答案

问题来自Apple的沙盒规则.您不再可以直接从VBA保存或打开到所需的任何文件夹.您只能写入Excel有权访问的文件夹.尽管我尚未测试,但这可能包括导出PDF.

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.

这里是Ron de Bruin的精彩页面,详细介绍了如何在VBA中处理Apple的沙盒问题.

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

这篇关于VBA将工作表导出为PDF(Mac 2016)错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆