使用Mac Excel VBA另存为pdf [英] Save as pdf using Mac Excel VBA
问题描述
在Mac OS上保存为PDF的My Excel VBA有时不起作用.
My Excel VBA on Mac OS to save as PDF sometimes doesn't work.
它将给予
打印时出错"
然后
运行时错误'1004':应用程序定义的错误或对象定义的错误".
"Run-time error '1004': Application-defined or object-defined error".
我的代码(昨天有效)
'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',则会出现上述错误.
I recorded the macro and used the code generated in my code (as below). It works. However, if I delete the last '9' in the code, I get the above error.
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"时却给出了错误.
I tried using PathSeparator, and again, with the last '9' it works but gives an error without the '9'.
推荐答案
以下是有关操作方法的指南: https://www.rondebruin.nl/mac/mac034.htm
Here is a guide on how you can do it: https://www.rondebruin.nl/mac/mac034.htm
重要的是您不能将文件保存到您选择的位置.
What's important is that you can't save your file to a location that is selected by you.
它必须保存到当前用户主目录下的文件夹 Library/Group Containers/UBF8T346G9.Office
中,因此/Users/[当前用户]/Library/Group Containers/在大多数情况下为UBF8T346G9.Office
.如果文件夹不存在,则必须创建它.(请参见上面链接页面上的代码示例)
It has to be saved to the folder Library/Group Containers/UBF8T346G9.Office
under the current user's home dir, so /Users/[current user]/Library/Group Containers/UBF8T346G9.Office
in most of the cases. If the folder is not there, you have to create it. (See the code example on the page linked above)
对罗恩表示敬意!
请对此投票,由MS进行修正: https://excel.uservoice.com/forums/304933-excel-for-mac/suggestions/36531559-fix-exportasfixedformat-method
Please vote for this to be fixed by MS here: https://excel.uservoice.com/forums/304933-excel-for-mac/suggestions/36531559-fix-exportasfixedformat-method
这篇关于使用Mac Excel VBA另存为pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!