Quantcast
Channel: Microsoft Community - Super Fresh
Viewing all articles
Browse latest Browse all 1237856

VBA Lotus Notes Email Works in Debug But Fails in Runtime

$
0
0

Hello,

I have a macro (Excel 2010) that will send an email through Lotus Notes 8.5 with no problem if ran through debug. However, when the code is fully ran it seems to get an error as shown below highlighted in red. The part that is tricky to me is that it seems to be random as to when it works and when it doesn't work. The error i receive is error 91, object or variable not set. If anyone can help in this matter, it would be very much appreciated. 

P.S. 

In a separate code, i was able to minimize the excel application while running the email macro and maximize the application when finished. This seemed to fix the problem, but i still sometimes get the error. 

Sub SENDEMAIL2()
Application.ScreenUpdating = False
Application.DisplayAlerts = False

Dim print1 As Worksheet
Dim HEADER As String
Set print1 = Sheets("PRINT")
Sheets("Analysis").Select
print1.Range("s1") = Range("e2").Value
print1.Range("t2") = Range("f3").Value
print1.Range("t3") = Range("f4").Value
print1.Select
Call printt
Sheets("Analysis").Select
If Range("F3") = "" Then
    HEADER = Range("F4").Text
Else
    HEADER = Range("F3").Text & " - " & Range("F4").Text
End If
print1.Select
Dim Notes As Object, db As Object, WorkSpace As Object
Dim UIdoc As Object, UserName As String, MailDbName As String
Set Notes = CreateObject("Notes.NotesSession")

UserName = Notes.UserName
MailDbName = Left$(UserName, 1) & Right$(UserName, _
(Len(UserName) - InStr(1, UserName, " "))) & ".nsf"

Set db = Notes.GETDATABASE(vbNullString, MailDbName)

Set WorkSpace = CreateObject("Notes.NotesUIWorkspace")
Call WorkSpace.ComposeDocument(, , "Memo")

Set UIdoc = WorkSpace.CurrentDocument

Call UIdoc.FieldAppendText("ENTERSendTo", "*** Email address is removed for privacy ***") 'Recipient
Call UIdoc.FieldAppendText("Subject", "CONTROL CHARTS: " & HEADER)

Dim last As Integer
Dim lastmax As Integer
last = Range("S16").Value
If last > 60 Then
    Range(Cells(61, 1), Cells(last, 20)).CopyPicture
    Call UIdoc.gotofield("Body")
    Call UIdoc.Paste
    Range(Cells(1, 1), Cells(60, 20)).CopyPicture
    Call UIdoc.gotofield("Body")
    Call UIdoc.InsertText(WorksheetFunction.Substitute( _
    "The Control Charts for " & HEAD & " are presented below:@@", _
    "@", vbCrLf))
    Call UIdoc.Paste

Else
    Range(Cells(1, 1), Cells(last, 20)).CopyPicture
    Call UIdoc.gotofield("Body")
    Call UIdoc.InsertText(WorksheetFunction.Substitute( _
    "The Control Charts for " & HEAD & " are presented below:@@", _
    "@", vbCrLf))
    Call UIdoc.Paste
End If

Application.CutCopyMode = False

UIdoc.Document.saveoptions = "0"
Call UIdoc.SEND(True)
Call UIdoc.Close

Set UIdoc = Nothing: Set WorkSpace = Nothing
Set db = Nothing: Set Notes = Nothing
Sheets("PRINT").Select
Call CLEARPRINT
Sheets("Analysis").Select
End Sub

    

Viewing all articles
Browse latest Browse all 1237856

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>