Chrismas007
Chrismas007

Reputation: 6105

Saving an Excel File as PDF on both Windows and Mac

I have created a macro to export my sheet as a PDF however some users in the company use Mac OS. When these users attempt to save, it gives them an error. How do I allow both Win and Mac users to use the same PDF export?

Here is my current code:

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

Upvotes: 1

Views: 5126

Answers (2)

ecramer
ecramer

Reputation: 341

VBA has Application.PathSeparator as well.

http://msdn.microsoft.com/en-us/library/office/ff820973%28v=office.15%29.aspx

Upvotes: 3

Chrismas007
Chrismas007

Reputation: 6105

I was unable to find the answer to this on SO, but came across this workaround to share:

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

Upvotes: 0

Related Questions