Hi All,
I'm trying to create a macro whereby it saves each worksheet separately as a PDF and then create a new email in Outlook (2016).
I have managed to save each worksheet as a PDF individually but to get the PDF as an attachment on Outlook or even have a new email created doesn't seem to work... Am I missing something blatantly obvious? Help please!!
Code below:
I'm trying to create a macro whereby it saves each worksheet separately as a PDF and then create a new email in Outlook (2016).
I have managed to save each worksheet as a PDF individually but to get the PDF as an attachment on Outlook or even have a new email created doesn't seem to work... Am I missing something blatantly obvious? Help please!!
Code below:
Code:
Sub ExportToPDFs()
Application.ScreenUpdating = False
Dim ws As Worksheet
Dim oApp As Object
Dim oMail As Object
Dim strFileName As String
For Each ws In Worksheets
ws.Select
nm = ws.Name
If Not ws.Name = "Master" _
And Not ws.Name = "Lookups" _
And Not ws.Name = "TB" _
And Not ws.Name = "Store Lookups" Then
strFileName = "X:\IT\Test\test\" & nm & ".pdf"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=strFileName, _
Quality:=xlQualityStandard, IncludeDocProperties:=True, _
IgnorePrintAreas:=False, OpenAfterPublish:=False
Set oApp = CreateObject("Outlook.Application")
Set oMail = oApp.CreateItem(0)
With oMail
.To = [I1]
.Subject = "test"
.body = "This is a test"
.Attachments.Add strFileName
End With
End If
Next ws
End Sub