在Windows和Mac上将Excel文件另存为PDF

我已经创build了一个macros来将我的工作表导出为PDF,但公司中的一些用户使用Mac OS。 当这些用户试图保存时,会给他们一个错误。 如何让Win和Mac用户使用相同的PDF导出?

这是我现在的代码:

Sub CreatePDF() Dim wksSheet As Worksheet Set wksSheet = ActiveSheet wksSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _ ThisWorkbook.Path & "\" & Range("exportName"), Quality:=xlQualityStandard, _ IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _ False End Sub 

Solutions Collecting From Web of "在Windows和Mac上将Excel文件另存为PDF"

我无法在SO上找到这个答案,但遇到这个解决方法分享:

 Sub CreatePDF() Dim wksSheet As Worksheet Dim TheOS As String TheOS = Application.OperatingSystem If InStr(1, TheOS, "Windows") > 0 Then Set wksSheet = ActiveSheet wksSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _ ThisWorkbook.Path & "\" & Range("exportName"), Quality:=xlQualityStandard, _ IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _ False Exit Sub Else Set wksSheet = ActiveSheet wksSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _ ThisWorkbook.Path & ":" & Range("exportName"), Quality:=xlQualityStandard, _ IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _ False Exit Sub End If End Sub