Mac excel VBA export to pdf with specific name from specific cells

Snakyiss

New Member
Joined
Jul 21, 2013
Messages
9
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
 

Attachments

  • screenshot of worksheet.jpg
    screenshot of worksheet.jpg
    181.9 KB · Views: 45

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.

Forum statistics

Threads
1,223,885
Messages
6,175,179
Members
452,615
Latest member
bogeys2birdies

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top