Hi all,
I've used this VBA code before with Excel 2003 and it worked flawlessly.
I am now using Excel 2016 and it debugs at ".Attachments.Add PDF_File" stage.
The PDF is being created in the correct location, the emailed is attempted to be opened with the warning window I created popping up. But alas the email doesn't get created or sent as it debugs.
I coloured in the line that debugs with red text.
Would love some help!
Thank you.
____________________________
I've used this VBA code before with Excel 2003 and it worked flawlessly.
I am now using Excel 2016 and it debugs at ".Attachments.Add PDF_File" stage.
The PDF is being created in the correct location, the emailed is attempted to be opened with the warning window I created popping up. But alas the email doesn't get created or sent as it debugs.
I coloured in the line that debugs with red text.
Would love some help!
Thank you.
____________________________
Code:
Sub MondayDAYPDF()
Dim olApp As Object
Path = "file location"
Salesman = ActiveSheet.Name & " Day Shift"
strDate = Format(Date, "yyyymmdd")
If i > 1 Then PDF_File = Left(PDF_File, i - 1)
PDF_File = Path & strDate & Salesman & ".pdf"
With Worksheets("Monday Shift Report").PageSetup
.Orientation = xlPortrait
End With
Sheets("Monday Shift Report").Range("A1:M56").ExportAsFixedFormat Type:=xlTypePDF, Filename:=PDF_File, Quality:= _
xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
OpenAfterPublish:=False
With Worksheets("Monday Shift Report").PageSetup
.PrintArea = "A1:M56"
.Zoom = False
.FitToPagesTall = 1
.FitToPagesWide = 1
End With
If MsgBox("Are you sure you are ready to send the shift report? If you are then please ensure Outlook is open before pressing OK. After sending, a confirmation box will show - if you do not see this box the e-mail may not have sent.", vbOK) = vbOK Then
'code to send message
Else
Exit Sub 'terminate macro
End If
Set Mail_Object = CreateObject("Outlook.Application")
With Mail_Object.CreateItem(o)
.Subject = "HR Operations Monday Day Shift Report"
.To = "destination email"
.Body = "HR Operations Monday Day Shift Report attached" & Chr(13) & Chr(13) & "Kind regards"
[COLOR=#ff0000].Attachments.Add PDF_File[/COLOR]
.Send
End With
MsgBox "E-mail successfully sent", 64
Application.DisplayAlerts = False
Set Mail_Object = Nothing
End Sub
Last edited by a moderator: