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

时间:2014-11-26 14:06:28

标签: windows excel macos vba excel-vba

我创建了一个宏来将我的工作表导出为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

2 个答案:

答案 0 :(得分:3)

答案 1 :(得分:0)

我无法在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