Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 在Mac上导出为PDF格式_Excel_Vba_Macos - Fatal编程技术网

Excel 在Mac上导出为PDF格式

Excel 在Mac上导出为PDF格式,excel,vba,macos,Excel,Vba,Macos,我有一个代码,可以将每个单独的选项卡导出为Excel文件所在文件夹中的PDF格式,它在Windows上正常工作,但在mac上由于错误“应用程序定义或对象定义错误”而失败,我一直在研究在mac上使用VBA,但似乎您需要将其保存在以前需要访问的完全不同的文件夹位置,对此有何解决方案?它可以在同一文件夹上工作,也可以在用户可以从打开的对话框窗口中选择的文件夹中工作。代码如下: Option Explicit Sub WorksheetLoop() Dim wsA As Worksheet

我有一个代码,可以将每个单独的选项卡导出为Excel文件所在文件夹中的PDF格式,它在Windows上正常工作,但在mac上由于错误“应用程序定义或对象定义错误”而失败,我一直在研究在mac上使用VBA,但似乎您需要将其保存在以前需要访问的完全不同的文件夹位置,对此有何解决方案?它可以在同一文件夹上工作,也可以在用户可以从打开的对话框窗口中选择的文件夹中工作。代码如下:

Option Explicit

Sub WorksheetLoop()

Dim wsA     As Worksheet
Dim wbA     As Workbook
Dim strTime As String
Dim strName As String
Dim strPath As String
Dim strFile As String
Dim strPathFile As String
Dim myFile  As Variant
Dim WS_Count As Integer
Dim I       As Integer
Dim fName As String

' Set WS_Count equal to the number of worksheets in the active workbook.
Set wbA = ActiveWorkbook
WS_Count = wbA.Worksheets.Count
strPath = wbA.Path
strTime = Format(Now(), "yyyymmdd\_hhmm")

'get active workbook folder, if saved
strPath = wbA.Path
If strPath = "" Then
    strPath = Application.DefaultFilePath
End If
strPath = strPath & "\"

' Begin the loop.
For Each wsA In wbA.Worksheets
    wsA.Activate
    'replace spaces and periods in sheet name
    strName = Replace(wsA.Name, " ", "")
    strName = Replace(strName, ".", "_")

    'create default name for savng file
    strFile = ActiveSheet.Range("D5").Value & ".pdf"
    myFile = strPath & strFile

    Debug.Print myFile

    'export to PDF if a folder was selected
    If myFile <> "False" Then
        ActiveSheet.ExportAsFixedFormat _
                Type:=xlTypePDF, _
                Filename:=myFile, _
                Quality:=xlQualityStandard, _
                IncludeDocProperties:=True, _
                IgnorePrintAreas:=False, _
                OpenAfterPublish:=False
        'confirmation message with file info
       
    End If

Next wsA
 MsgBox "Your PDF files have been created: "
 Worksheets("Summary").Activate
               
End Sub
选项显式
子工作表loop()
将wsA设置为工作表
将wbA设置为工作簿
作为字符串的Dim strTime
将strName设置为字符串
将strPath设置为字符串
作为字符串的Dim strFile
将strPathFile设置为字符串
Dim myFile作为变量
Dim WS_计数为整数
作为整数的Dim I
作为字符串的Dim fName
'将WS_Count设置为活动工作簿中的工作表数。
设置wbA=ActiveWorkbook
WS_Count=wbA.Worksheets.Count
strPath=wbA.Path
strTime=格式(现在(),“yyyymmdd\ \u hhmm”)
'获取活动工作簿文件夹(如果已保存)
strPath=wbA.Path
如果strPath=“”,则
strPath=Application.DefaultFilePath
如果结束
strPath=strPath&“\”
'开始循环。
对于wbA.工作表中的每个wsA
wsA,激活
'替换图纸名称中的空格和句点
strName=Replace(wsA.Name,“,”)
strName=Replace(strName,“.”,“”)
'为savng文件创建默认名称
strFile=ActiveSheet.Range(“D5”).Value&“.pdf”
myFile=strPath和strFile
调试。打印我的文件
'如果选择了文件夹,则导出为PDF
如果myFile为“False”,则
ActiveSheet.ExportAsFixedFormat_
类型:=xlTypePDF_
文件名:=myFile_
质量:=xlQualityStandard_
IncludeDocProperties:=True_
IgnorePrintAreas:=假_
OpenAfterPublish:=False
'带有文件信息的确认消息
如果结束
下一个wsA
MsgBox“您的PDF文件已创建:”
工作表(“摘要”)。激活
端接头

这听起来像是Mac上的“沙箱”问题。从Office 2016开始,苹果要求微软限制Excel VBA可以保存文件的文件夹

我不太确定您希望如何调整代码以使其正常工作,但Ron de Bruin有一个关于Excel VBA的很棒的网站,还有一个关于在Mac上执行的特别有用的部分。此特定页面讨论了沙箱问题,并解释了您应该能够将文件保存到哪些特定文件夹而不会出现任何问题


我问了几个问题来说明如何在mac上进行路径设置。谢谢你,迈克,似乎找不到你的问题,因为我也对它做了一些研究,但没有找到与MacWell文件夹相同的路径,我这里只有9个问题,所以这不应该是太大的挑战。。。但这里有一个给你一个想法,如果它给你一些帮助,给它投票:或者这个: