Jak68
New Member
- Joined
- Jan 21, 2016
- Messages
- 17
Hi, I have a spreadsheet with some code to help send an email (when I run the code) when a certain date is reached.
The code was originally set up to work with Lotus Notes but we are finally using outlook.
Could someone please help me to change the code to run in Outlook and also is it possible for the code to run automatically without having to press any buttons? Thanks
Here is the code I use:
Sub sendemail()
Dim WatchRange As Range
Dim IntersectRange As Range
Dim x As Integer
Dim UserName As String
Dim MailDbName As String
Dim Recipient As Variant
Dim Maildb As Object
Dim MailDoc As Object
Dim AttachME 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 = 5 To Cells(Rows.Count, "O").End(xlUp).row
If (Range("O" & x).Value <> "OK") And (Range("P" & x).Value <> "Yes") 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 = "Message"
'stSignature = Maildb.GetProfileDocument("CalendarProfile").GetItemValue("Signature")(0)
' Select range of e-mail addresses
'Recipient = Worksheets("Sheet1").Range("B" & x).Value
MailDoc.SendTo = "my email address"
MailDoc.Subject = "Calibration on this item is now due! - " & Range("B" & x).Value
MailDoc.Body = "This item is now due for calibration, please arrange for this to be completed ASAP."
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
The code was originally set up to work with Lotus Notes but we are finally using outlook.
Could someone please help me to change the code to run in Outlook and also is it possible for the code to run automatically without having to press any buttons? Thanks
Here is the code I use:
Sub sendemail()
Dim WatchRange As Range
Dim IntersectRange As Range
Dim x As Integer
Dim UserName As String
Dim MailDbName As String
Dim Recipient As Variant
Dim Maildb As Object
Dim MailDoc As Object
Dim AttachME 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 = 5 To Cells(Rows.Count, "O").End(xlUp).row
If (Range("O" & x).Value <> "OK") And (Range("P" & x).Value <> "Yes") 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 = "Message"
'stSignature = Maildb.GetProfileDocument("CalendarProfile").GetItemValue("Signature")(0)
' Select range of e-mail addresses
'Recipient = Worksheets("Sheet1").Range("B" & x).Value
MailDoc.SendTo = "my email address"
MailDoc.Subject = "Calibration on this item is now due! - " & Range("B" & x).Value
MailDoc.Body = "This item is now due for calibration, please arrange for this to be completed ASAP."
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