How to Combine a Save As PDF macro and an E-Mail send macro???

GranolDad

New Member
Joined
Dec 7, 2016
Messages
1
I have the following as a save as macro:

Sub SaveMyPDF()
'
' SaveMyPDF Macro
'
On Error GoTo ende
' First range B5 is client acroynym.
' Second range I4 is one letter.
' Thrid range B3 is name.
' Forth range is WE date.
' Fifth range is file format.
' Should save as example XXX-X-for-John Dow.-WE-112616.pdf
' strFolderPath = "C:\1. Aquitas\Time and Expenses"
' Sheet1.Range("K3").Value & _

Dim strPath As String
Dim strFolderPath As String
strFolderPath = Sheet1.Range("F2").Value
strPath = strFolderPath & _
Sheet1.Range("A2").Value & "-" & _
Sheet1.Range("B2").Value & "-for-" & _
Sheet1.Range("C2").Value & "-WE-" & _
Sheet1.Range("D2").Value & ".pdf"

ActiveSheet.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=strPath

ende:
Set app = Nothing
Set itm = Nothing

End Sub


I also have an E-Mail Send macro:

Sub EmailSend()
'
' EmailSend Macro
'
Dim outlookOBJ As Object
Dim mItem As Object
Set outlookOBJ = CreateObject("Outlook.Application")
Set mItem = outlookOBJ.CreateItem(olMailItem)
With mItem
.To = Range("B3").Value
.CC = Range("E3").Value
.Subject = Range("I3").Value
.Body = Range("M3").Value & vbCrLf & vbCrLf & Range("N3")
.Attachments.Add ThisWorkbook.Path & "" & ThisWorkbook.Name
.Send

End With
End Sub

My Question is how can I combine these so an E-Mail is sent with the correct file name and is a PDF?
Is it possible?



Wine a bit
you'll feel better
Todd.gif
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.

baitmaster

Well-known Member
Joined
Mar 12, 2009
Messages
2,042
welcome to the board

Try this:
Code:
Dim strPath As String
Function SaveMyPDF() As Boolean
'
' SaveMyPDF Macro
'
On Error GoTo ende
' First range B5 is client acroynym.
' Second range I4 is one letter.
' Thrid range B3 is name.
' Forth range is WE date.
' Fifth range is file format.
' Should save as example XXX-X-for-John Dow.-WE-112616.pdf
' strFolderPath = "C:\1. Aquitas\Time and Expenses"
' Sheet1.Range("K3").Value & _
Dim strFolderPath As String
strFolderPath = Sheet1.Range("F2").value
strPath = strFolderPath & _
Sheet1.Range("A2").value & "-" & _
Sheet1.Range("B2").value & "-for-" & _
Sheet1.Range("C2").value & "-WE-" & _
Sheet1.Range("D2").value & ".pdf"
ActiveSheet.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=strPath
SaveMyPDF = True
ende:
Set app = Nothing
Set itm = Nothing
End Function
 
Sub EmailSend()
'
' EmailSend Macro
'
If Not SaveMyPDF Then
    MsgBox "ERROR: cannot create PDF. Unable to continue", vbCritical
    Exit Sub
End If
Dim outlookOBJ As Object
Dim mItem As Object
Set outlookOBJ = CreateObject("Outlook.Application")
Set mItem = outlookOBJ.CreateItem(olMailItem)
With mItem
.To = Range("B3").value
.CC = Range("E3").value
.Subject = Range("I3").value
.Body = Range("M3").value & vbCrLf & vbCrLf & Range("N3")
.Attachments.Add strPath
.Send
End With
End Sub
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,280
Messages
5,836,370
Members
430,424
Latest member
ALHK022

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
Top