Boa noite,
tenho uma macro que envia um email automático pegando alguns valores de uma planilha como destinatário e parte do corpo do email que está rodando bem na primeira volta do loop. Quando ela passa para a segunda volta ocorre um erro "Run-time error '91': Object variable or With block variable not set"
Segue meu código
Sub teste()
'Set up the objects required for Automation into lotus notes
Dim Maildb As Object 'The mail database
Dim UserName As String 'The current users notes name
Dim MailDbName As String 'The current users notes mail database name
Dim MailDoc As Object 'The mail document itself
Dim AttachME As Object 'The attachment richtextfile object
Dim Session As Object 'The notes session
Dim recip As Variant
Dim ccrecip(0 To 1) As Variant
Dim cont As Integer
'Start a session to notes
Set Session = CreateObject("Notes.NotesSession")
UserName = Session.UserName
MailDbName = Left$(UserName, 1) & Right$(UserName, (Len(UserName) - InStr(1, UserName, " "))) & ".nsf"
'Open the mail database in notes
Set Maildb = Session.GETDATABASE("", MailDbName)
If Maildb.IsOpen = True Then
'Already open for mail
Else
Maildb.OPENMAIL
End If
'Set up the new mail document
Set MailDoc = Maildb.CREATEDOCUMENT
Workbooks("Pipeline Report Consolidate").Sheets("Hist").Range("C7").Select
'Checa se o email já foi mandado para essa lista
Do While ActiveCell.Value <> ""
ActiveCell.Offset(0, 24).Select
If ActiveCell.Value = "OK" Then
GoTo prox
End If
Workbooks("Pipeline Report Consolidate").Sheets("Hist").Range("status").Select
Do While ActiveCell.Value <> ""
ActiveCell.Offset(1, 0).Select
cont = cont + 1
Loop
recip = Cells(cont + 6, 24).Value
If IsNumeric(ActiveCell.Offset(0, -2)) = False Then
ccrecip(0) = Cells(cont + 6, 25).Value
If IsNumeric(ActiveCell.Offset(0, -1)) = False Then
ccrecip(1) = Cells(cont + 6, 26).Value
End If
End If
cliente = Cells(cont + 6, 5).Value
dias = Cells(cont + 6, 23).Value
MailDoc.sendto = recip ------> (É NESSA LINHA QUE O ERRO OCORRE NA SEGUNDA VOLTA DO LOOP, NA PRIMEIRA RODA DIREITINHO)
If IsNumeric(ActiveCell.Offset(0, -2)) = False Then
MailDoc.copyto = ccrecip(0)
If IsNumeric(ActiveCell.Offset(0, -1)) = False Then
MailDoc.copyto = ccrecip(1)
End If
End If
MailDoc.Subject = "Reminder de Follow up"
MailDoc.Body = "Você tem um Follow up agendado com o cliente " & cliente & " em " & dias & " dias."
MailDoc.SAVEMESSAGEONSEND = True
'Send the document
MailDoc.PostedDate = Now() 'Gets the mail to appear in the sent items folder
MailDoc.send 0, recip
'Clean Up
Set Maildb = Nothing
Set MailDoc = Nothing
Set AttachME = Nothing
Set Session = Nothing
Set EmbedObj = Nothing
prox:
ActiveCell.Value = "OK"
ActiveCell.Offset(1, -24).Select
cont = 0
Loop
End Sub
Alguém pode me ajudar?