【发布时间】:2018-09-24 05:26:10
【问题描述】:
我在 Mac OS 上保存为 PDF 的 Excel VBA 有时不起作用。
它会给你
“打印时出错”
然后
“运行时错误'1004':应用程序定义或对象定义的错误”。
我的代码,昨天有效:
'a) For Windows
Dim wksSheet As Worksheet, PS As String
PS = Application.PathSeparator
If InStr(1, Application.OperatingSystem, "Windows") > 0 Then
Set wksSheet = ActiveSheet
wksSheet.ExportAsFixedFormat Type:=xlTypePDF, FileName:= _
ThisWorkbook.Path & PS & pdfName, Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
False
'Exit Sub
Else
'b) For MAC
Dim pdfName As String, FullName As String
pdfName = "Q - " & Range("F2").Value & " - " & Range("A2").Value & " - " & Range("B10").Text
FullName = "/Users/" & QTGetUserNameMAC & "/Google Drive/ABC Pte Ltd/Q - Quotations/" _
& pdfName & ".pdf"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, FileName:=FullName _
, Quality:=xlQualityMinimum, IncludeDocProperties:=True, IgnorePrintAreas _
:=False, OpenAfterPublish:=False
End If
我录制了宏并使用了我的代码中生成的代码(如下所示)。有用。但是,如果我删除代码中的最后一个“9”,就会出现上述错误。
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, FileName:= _
"/Users/" & QTGetUserNameMAC & "/Google Drive/ABC Pte Ltd/Q - Quotations/Q - VAS-Quote-QT190039.pdf" _
, Quality:=xlQualityMinimum, IncludeDocProperties:=True, IgnorePrintAreas _
:=False, OpenAfterPublish:=False
我尝试使用 PathSeparator,并且再次使用最后一个 '9' 它可以工作,但没有 '9' 会出现错误。
【问题讨论】: