Hi all,
Im trying to create a vba codes that work on both windows and Mac, Windows is fine but it doesnt work on Excel 2016 for Mac, it will goes directly to "Print" page to choose printer and print (without exporting to pdf and saving pdf file under a specific name referring cell in the worksheet).
I have tried to refer to this post from this link but i still unable to get this right, Make and Mail PDF files with VBA code on your Mac
I have attached the screenshot of my worksheet so you can get an idea of what file name i wish to appear, this code also will change the document number and jump to next number when the save button is being clicked.
Please help
Many thanks in advance.
this is my code:
Sub save()
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:= _
Format(Now, "yyyymmdd") & " Invoice - " & Range("B16").Value & ".pdf", Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
True
Range("M5").Value = Range("M5").Value + 1
Range("B24:D34").ClearContents
Exit Sub
Else
Dim pdfName As String, FullName As String
pdfName = Format(Now, "yyyymmdd") & " Invoice - " & Range("B16").Value & ".pdf"
FullName = "/Users/[current user]/Library/Group Containers/UBF8T346G9.Office" & Format(Now, "yyyymmdd") & " Invoice - " & Range("B16").Value & ".pdf"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"/Users/[current user]/Library/Group Containers/UBF8T346G9.Office" & Format(Now, "yyyymmdd") & " Invoice - " & Range("B16").Value & ".pdf" _
, Quality:=xlQualityMinimum, IncludeDocProperties:=True, IgnorePrintAreas _
:=False, OpenAfterPublish:=False
Range("M5").Value = Range("M5").Value + 1
Range("B24:D34").ClearContents
Exit Sub
End If
End Sub
Im trying to create a vba codes that work on both windows and Mac, Windows is fine but it doesnt work on Excel 2016 for Mac, it will goes directly to "Print" page to choose printer and print (without exporting to pdf and saving pdf file under a specific name referring cell in the worksheet).
I have tried to refer to this post from this link but i still unable to get this right, Make and Mail PDF files with VBA code on your Mac
I have attached the screenshot of my worksheet so you can get an idea of what file name i wish to appear, this code also will change the document number and jump to next number when the save button is being clicked.
Please help
Many thanks in advance.
this is my code:
Sub save()
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:= _
Format(Now, "yyyymmdd") & " Invoice - " & Range("B16").Value & ".pdf", Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
True
Range("M5").Value = Range("M5").Value + 1
Range("B24:D34").ClearContents
Exit Sub
Else
Dim pdfName As String, FullName As String
pdfName = Format(Now, "yyyymmdd") & " Invoice - " & Range("B16").Value & ".pdf"
FullName = "/Users/[current user]/Library/Group Containers/UBF8T346G9.Office" & Format(Now, "yyyymmdd") & " Invoice - " & Range("B16").Value & ".pdf"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"/Users/[current user]/Library/Group Containers/UBF8T346G9.Office" & Format(Now, "yyyymmdd") & " Invoice - " & Range("B16").Value & ".pdf" _
, Quality:=xlQualityMinimum, IncludeDocProperties:=True, IgnorePrintAreas _
:=False, OpenAfterPublish:=False
Range("M5").Value = Range("M5").Value + 1
Range("B24:D34").ClearContents
Exit Sub
End If
End Sub