ActiveSheet.ExportAsFixedFormat on a Mac not printing in landscape orientation

MalcolmDS

New Member
Joined
Dec 27, 2018
Messages
2
Hi,

Excel 2016.
I am trying to send a PDF in landscape orientation by mail using the ActiveSheet.ExportAsFixedFormat function.
If I try printing the sheet it manually it works fine in landscape.
But it does not work in VBA. I have googled this issue extensively for no solution.

Code:
Sub SaveMailActiveSheetAsPDFIn2016Sierra(strBody As String, strSubject As String, toAddress As String, Optional landscape As Boolean)
    'Ron de Bruin : 10-March-2018
    'There is no option for a signature because of a bug in Sierra
    Dim FileName As String
    Dim FolderName As String
    Dim Folderstring As String
    Dim FilePathName As String


    'Check for AppleScriptTask script file that we must use to create the mail
    If CheckAppleScriptTaskExcelScriptFile(ScriptFileName:="RDBMacMail.scpt") = False Then
        MsgBox "Sorry the RDBMacMail.scpt is not in the correct location"
        Exit Sub
    End If


    'If my ActiveSheet is landscape, I must attach this line
    'for making the PDF also landscape, seems to default to xlPortait
    'ActiveSheet.PageSetup.Orientation = ActiveSheet.PageSetup.Orientation
    
    With ActiveSheet.PageSetup
            .Zoom = False
            .FitToPagesWide = 1
            .LeftMargin = Application.InchesToPoints(0)
            .RightMargin = Application.InchesToPoints(0)
           ' .PrintArea = ActiveSheet.UsedRange
            If landscape = True Then
                .Orientation = xlLandscape
            End If
    End With
         
    'Name of the folder in the Office folder
    FolderName = "TempPDFFolder"
    'Name of the pdf file
    FileName = Format(Now, "hh-mm-ss") & ".pdf"


    Folderstring = CreateFolderinMacOffice2016(NameFolder:=FolderName)
    FilePathName = Folderstring & Application.PathSeparator & FileName


    'Create the body text in the strbody string
 
    'expression A variable that represents a Workbook, Sheet, Chart, or Range object.
    'The parameters are not working like in Excel for Windows
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, FileName:= _
    FilePathName, Quality:=xlQualityStandard, _
    IncludeDocProperties:=True, IgnorePrintAreas:=False
    
    Dim addresses As Variant
    Dim i As Integer
    Dim ccaddress As String
    
    addresses = Split(toAddress, ",")
    For i = 1 To UBound(addresses)
        ccaddress = ccaddress & "," & addresses(i)
    Next
    
    'Call the MacExcel2016WithMacMailPDFSierra function to create the mail
    'When you use more mail addresses separate them with a ,
    'Change yes to no in the displaymail argument to send directly
    'Look in Mail>Preferences for the name of the mail account
    'Sender name looks like this : "Your Name <your@mailaddress.com>"
    MacExcel2016WithMacMailPDFSierra subject:=strSubject, _
    mailbody:=strBody, _
    toAddress:=CStr(addresses(0)), _
    ccaddress:=ccaddress, _
    bccaddress:="", _
    attachment:=FilePathName, _
    displaymail:="yes", _
    thesender:=""
End Sub
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().

Forum statistics

Threads
1,214,908
Messages
6,122,187
Members
449,071
Latest member
cdnMech

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