KarelDeGrote
New Member
- Joined
- Dec 11, 2018
- Messages
- 8
Hi all,
I have created a macro piece by piece using this form, but now I am stuck with it, hope someone can help.
I have macro which is used to send a pdf file to an email address if the cell containing the email address do have a value.
Now I would like to add a code to print the pdf file on a default printer if the cell is blank. So send an email when there is an email address and print the pdf file when the cell with email address is empty (and send by regular mail).
I have created a macro piece by piece using this form, but now I am stuck with it, hope someone can help.
I have macro which is used to send a pdf file to an email address if the cell containing the email address do have a value.
Now I would like to add a code to print the pdf file on a default printer if the cell is blank. So send an email when there is an email address and print the pdf file when the cell with email address is empty (and send by regular mail).
Code:
Sub SendEmailfromOutlook()
Sheets("Email list").Activate
Dim OutApp As Object
Dim OutMail As Object
Dim cell As Range
Dim Path As String
Path = Application.ActiveWorkbook.Path
Set OutApp = CreateObject("Outlook.Application")
For Each cell In Range("j3:j50")
If cell.Value <> "" Then
Set OutMail = OutApp.CreateItem(0)
With OutMail
.SentOnBehalfOfName = "test@test.com"
.To = cell.Value
.Subject = Cells(cell.Row, "A").Value
.Body = "Dear Sir/ Madam," _
.Attachments.Add (Path & "\" & Cells(cell.Row, "L").Value)
'.Send
.Save
End With
End If
Next cell
End Sub