PDA

View Full Version : Excel attachment with lotus notes



dilipramadas
08-24-2010, 08:41 AM
Hey all,
This code makes the sends the email, i want it to stop for a manual check before the email is sent. Can anyone simplify this? And i want to add matter to the email as well.

Sub LotusMail()
' setting up various objects
Dim Maildb As Object
Dim UserName As String
Dim MailDbName As String
Dim MailDoc As Object
Dim attachME As Object
Dim Session As Object
Dim EmbedObj1 As Object
Dim recipient As String
Dim ccRecipient As String
Dim bccRecipient As String
Dim subject As String
Dim bodytext As String
Dim Attachment1 As String
' setting up all sending recipients
recipient = "email@website.com"
copyto = "email@website.com"
'bccRecipient = ""
subject = "Test"
bodytext = "Test mail" & vbCrLf & "Test 2" & vbCrLf & vbCrLf & ""

'// Lets check to see if form is filled in Min req =Recipient, Subject, Body Text
If recipient = vbNullString Or subject = vbNullString Or bodytext = vbNullString Then
MsgBox "Recipient, Subject and or Body Text is NOT SET!", vbCritical + vbInformation
Exit Sub
End If
' creating a notes session
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)
Set Maildb = Session.GETDATABASE("", "")
If Maildb.IsOpen <> True Then
On Error Resume Next
Maildb.OPENMAIL
End If
Set MailDoc = Maildb.CreateDocument
MailDoc.Form = "Memo"
' loading the lotus notes e-mail with the inputed data
With MailDoc
.SendTo = recipient
.copyto = ccRecipient
'.blindcopyto = bccRecipient
.subject = subject
.Body = bodytext
End With
' saving message
MailDoc.SaveMessageOnSend = True
Attachment1 = "G:\Dilip\Testing for Mail send.xls"
If Attachment1 <> "" Then
Set attachME = MailDoc.CreateRichTextItem(Attachment1)
Set EmbedObj1 = attachME.EmbedObject(1454, "", Attachment1, "Attachment")
MailDoc.CreateRichTextItem ("Attachment")
End If
' send e-mail !!!!
MailDoc.PostedDate = Now()
' if error in attachment or name of recipients
On Error GoTo errorhandler1
MailDoc.Send 0, recipient
Set Maildb = Nothing
Set MailDoc = Nothing
Set attachME = Nothing
Set Session = Nothing
Set EmbedObj1 = Nothing
'Unload Me
Exit Sub
' setting up the error message
errorhandler1:
MsgBox "Incorrect name supplied or the attachment has not attached," & _
"or your Lotus Notes has not opened correctly. Recommend you open up Lotus Notes" & _
"to ensure the application runs correctly and that a vaild connection exists"
Set Maildb = Nothing
Set MailDoc = Nothing
Set attachME = Nothing
Set Session = Nothing
Set EmbedObj1 = Nothing
' unloading the userform
'Unload Me
End Sub

Kenneth Hobs
08-24-2010, 11:34 AM
Comment out: MailDoc.Send 0, recipient

See http://vbaexpress.com/forum/showthread.php?t=21561

mohitstellar
02-21-2011, 04:35 AM
The reason behind the occurrence of such error is NSF file corruption. To Repair NSF Files, you can try Stellar Lotus Notes Recovery software which is an excellent software to repair corrupt NSF file and recovers all emails, calendar entries, notes, tasks, journals, attachments and address books. Lotus Notes Recovery software is an advanced and powerful tool which scans, repairs NSF files & performs quick recovery of corrupted NSF file components.