Solved Mac Excel Macro to print a worksheet as PDF

Microsoft Excel 2013 32/64-bit - license...
November 22, 2018 at 14:08:46
Specs: Macintosh
Hi folks, I need to print Mac Excel sheet to PDF quite often, here are the VBA code used to be working fine with my Office 2011, but it does't work in Office 2016/2019, the macro is to print sheet to a fixed location, with file name format Invoice+sheet tab name, when I run the macro, it will highlight "PublishiOption:=, and says "Compile error: Name argument not found", can anyone please tell me how to rectify it? thank you in advance

Sub SaveInvoice()

' SavePDF Macro
' Save sheet to PDF
'
' Keyboard Shortcut: Option+Cmd+e
'
ActiveSheet.Copy
Range("A1:J60").Select
ActiveWorkbook.SaveAs FileName:= _
"MBP2018:Users:Jackcai:Dropbox:Temp PDF:Invoice.pdf", FileFormat:=xlPDF, _
PublishOption:=xlSheet
ActiveWorkbook.Close (False)
'
End Sub


See More: Mac Excel Macro to print a worksheet as PDF

Reply ↓  Report •

#1
November 22, 2018 at 16:24:37
✔ Best Answer
I don't have a Mac so I can't help directly, but...

Have you tried recording a macro while you do a Save As and choosing PDF as the File Type? I would think that the VBA Recorder would use whatever commands are valid for the version you have installed.

I just did that on my PC with Excel 2013 and got the following:

Sub Macro2()
'
' Macro2 Macro
'

'
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
        "C:\Users\MyUserName\Documents\Book1.pdf", Quality:=xlQualityStandard, _
        IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
        False
End Sub

BTW...What are these 2 instructions for? They don't seem to be related to the SaveAs function.

ActiveSheet.Copy
Range("A1:J60").Select

message edited by DerbyDad03


Reply ↓  Report •
Related Solutions


Ask Question