Bryan.GDL
05-06-2014, 03:22 PM
I'm new to Vba and was wondering if someone could help me? I'm trying to append my Signature while sending automatic emails from Macro.
But I keep getting this error message :
Run-time error '91':
Object variable or With block variable not set.
Here is the code I'm using.
Sub SendEmailUsingCOM()
Dim Maildb As Object
Dim MailDoc As Object
Dim SigText As String
Dim rtitem As Object 'NotesRichTextItem
Dim nSess As Object 'NotesSession
Dim nDir As Object 'NotesDbDirectory
Dim nDb As Object 'NotesDatabase
Dim nDoc As Object 'NotesDocument
Dim nAtt As Object 'NotesRichTextItem
Dim vToList As Variant, vCCList As Variant, vBCCList As Variant, vBody As Variant
Dim vbAtt As VbMsgBoxResult
Dim sFilPath As String
Dim sPwd As String
Set nSess = CreateObject("Lotus.NotesSession") 'New:{29131539-2EED-1069-BF5D-00DD011186B7}
sPwd = Application.InputBox("Type your Lotus Notes password!", Type:=2)
Call nSess.Initialize(sPwd)
Set nDir = nSess.GetDbDirectory("")
Set nDb = nDir.OpenMailDatabase
Set nDoc = nDb.CreateDocument
vToList = Application.Transpose(Range("A1").Resize(Range("A" & Rows.Count).End(xlUp).Row).Value)
vCCList = Application.Transpose(Range("B1").Resize(Range("B" & Rows.Count).End(xlUp).Row).Value)
vBCCList = Application.Transpose(Range("C1").Resize(Range("C" & Rows.Count).End(xlUp).Row).Value)
vBody = Application.Transpose(Range("D1").Resize(Range("D" & Rows.Count).End(xlUp).Row).Value)
With nDoc
Set nAtt = .CreateRichTextItem("Body")
SigText = Maildb.GetProfileDocument("CalendarProfile").GetItemValue("Signature")(0)
Call .ReplaceItemValue("Form", "Memo")
Call .ReplaceItemValue("Subject", "Inactive account reminder")
Call .ReplaceItemValue("blindcopyto", vBCCList)
With nAtt
.AppendText (Range("D2").Value)
Call nAtt.AppendText(BodyText)
Call nAtt.AppendText(SigText)
End With
Call .ReplaceItemValue("CopyTo", vCCList)
Call .ReplaceItemValue("PostedDate", Now())
Call .Send(True, vToList)
End With
End Sub
But I keep getting this error message :
Run-time error '91':
Object variable or With block variable not set.
Here is the code I'm using.
Sub SendEmailUsingCOM()
Dim Maildb As Object
Dim MailDoc As Object
Dim SigText As String
Dim rtitem As Object 'NotesRichTextItem
Dim nSess As Object 'NotesSession
Dim nDir As Object 'NotesDbDirectory
Dim nDb As Object 'NotesDatabase
Dim nDoc As Object 'NotesDocument
Dim nAtt As Object 'NotesRichTextItem
Dim vToList As Variant, vCCList As Variant, vBCCList As Variant, vBody As Variant
Dim vbAtt As VbMsgBoxResult
Dim sFilPath As String
Dim sPwd As String
Set nSess = CreateObject("Lotus.NotesSession") 'New:{29131539-2EED-1069-BF5D-00DD011186B7}
sPwd = Application.InputBox("Type your Lotus Notes password!", Type:=2)
Call nSess.Initialize(sPwd)
Set nDir = nSess.GetDbDirectory("")
Set nDb = nDir.OpenMailDatabase
Set nDoc = nDb.CreateDocument
vToList = Application.Transpose(Range("A1").Resize(Range("A" & Rows.Count).End(xlUp).Row).Value)
vCCList = Application.Transpose(Range("B1").Resize(Range("B" & Rows.Count).End(xlUp).Row).Value)
vBCCList = Application.Transpose(Range("C1").Resize(Range("C" & Rows.Count).End(xlUp).Row).Value)
vBody = Application.Transpose(Range("D1").Resize(Range("D" & Rows.Count).End(xlUp).Row).Value)
With nDoc
Set nAtt = .CreateRichTextItem("Body")
SigText = Maildb.GetProfileDocument("CalendarProfile").GetItemValue("Signature")(0)
Call .ReplaceItemValue("Form", "Memo")
Call .ReplaceItemValue("Subject", "Inactive account reminder")
Call .ReplaceItemValue("blindcopyto", vBCCList)
With nAtt
.AppendText (Range("D2").Value)
Call nAtt.AppendText(BodyText)
Call nAtt.AppendText(SigText)
End With
Call .ReplaceItemValue("CopyTo", vCCList)
Call .ReplaceItemValue("PostedDate", Now())
Call .Send(True, vToList)
End With
End Sub