VBA Macro to send email from Excel Crashing

PWHITTAK

New Member
Joined
Dec 8, 2017
Messages
3
Urgently need some help completing this macro

I found this code on your Forum posted by John Davis (edited post by George Hart). I have edited it to suit my needs but is gives me an Active X error and fails. I have added a variant for the title. I want it to run automatically each day and go through column K to find Reminder Due and send a mail containing
I am getting an Active X error message and macro fails.

I would also like to Mark Column L for each reminder sent with "Reminder Sent & date.

Sub PennyW()


Dim x As Integer
Dim UserName As String
Dim MailDbName As String
Dim Recipient As Variant
Dim Contents As Variant
Dim Maildb As Object
Dim MailDoc As Object


Dim Session As Object
Dim stSignature As String


With Application


.ScreenUpdating = False
.DisplayAlerts = False


' Open and locate current LOTUS NOTES User


For x = 3 To Cells(Rows.Count, "K").End(xlUp).Row


If Range("K" & x) = "Reminder Due" Then


Set Session = CreateObject("Notes.NotesSession")
UserName = Session.UserName
MailDbName = Left$(UserName, 1) & Right$(UserName, (Len(UserName) - InStr(1, UserName, " "))) & ".nsf"
Set Maildb = Session.GetDatabase("", MailDbName)
If Maildb.IsOpen = True Then
Else
Maildb.OPENMAIL
End If


' Create New Mail and Address Title Handlers


Set MailDoc = Maildb.CREATEDOCUMENT


MailDoc.Form = "Memo"




' Select range of e-mail addresses
Recipient = Worksheets("Sheet1").Range("I" & x).Value

'Select a range of Body
Contents= Worksheets("Sheet1").Range("H" & x).Value


MailDoc.SendTo = Recipient
MailDoc.Subject = "Contract Renewal Reminder"
MailDoc.Body = Contents


MailDoc.SaveMessageOnSend = True


MailDoc.PostedDate = Now()
On Error GoTo errorhandler1
MailDoc.Send 0, Recipient


Set Maildb = Nothing
Set MailDoc = Nothing
Set Session = Nothing


.ScreenUpdating = True
.DisplayAlerts = True


errorhandler1:
Set Maildb = Nothing
Set MailDoc = Nothing
Set Session = Nothing
End If
Next x
End With
End Sub


Any help appreciated.
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).

Forum statistics

Threads
1,223,705
Messages
6,173,996
Members
452,542
Latest member
Bricklin

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
Back
Top