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.
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