我在 Mac OS 上使用 Excel VBA 保存为 PDF 有时不起作用。
它会给
“打印时出错”
then
“运行时错误‘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”,则会出现错误。