简体   繁体   中英

VBA code print to pdf in Excel on Mac (Landscape and file destination)

I have looked at several solutions to this problem, but it is still not working, hopefully someone can help me find the reason.

I use Office 365 on MacOs 12.4 (Monterrey)

I want to print my spreadsheet as Landscape to a.pdf file, but every time it prints as Portrait As far as I can see it is a bit difficult to choose the file path on MacOs due to sandboxing. So far I haven't been able to get that to work, it will only output to the Excel folder.

I am using the following code:

   
Sheets(1).Select
Range("A1:CH55").Select
ActiveSheet.PageSetup.PrintArea = "$A$1:$CH$55"
With ActiveSheet.PageSetup
    .Orientation = xlLandscape
    .FitToPagesWide = 1
    .FitToPagesTall = 1
End With
    
    Range("A1:CH55").Select
    Selection.ExportAsFixedFormat Type:=xlTypePDF, FileName:="name.pdf", Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False

So my 2 questions are:

  1. How do I decide the output folder?
  2. How do I get the macro to print in Landscape?

After a long search I found a workaround and a solution.

  1. Ron de Bruin's website www.macexcel.com has code that sort of fixes that. I just hadn't copied the function part of the code, so that is why it didn't work.

  2. Ron de Bruin mentions that it is a bug. I couldn't get his bug fix to work, so I had to rethink how I wanted the document printed, so I could print it as portrait.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM