Link to home
Start Free TrialLog in
Avatar of jdpjtp910
jdpjtp910Flag for United States of America

asked on

VBA Code to disable signature in Lotus Notes

Good morning,
I have taken several samples of code from Internet and tweaked/added my own to it. The code I have will open a Memo and fill in the subject, send to field, and attach files without sending until user presses button within Lotus.
Here is the code:
Sub LotusNotsSendActiveWorkbook()
'Send an e-mail & attachment using Lotus Not(s)
'Declare Variables for file and macro setup
Dim UserName As String, MailDbName As String, ccRecipient As String, attachment1 As String
Dim Maildb As Object, MailDoc As Object, AttachME As Object, Session As Object
Dim EmbedObj1 As Object


With Application
.ScreenUpdating = False
.DisplayAlerts = False

' Open and locate current LOTUS NOTES User
Set Session = CreateObject("Notes.NotesSession")
UserName = Session.UserName
MailDbName = _
Left$(UserName, 1) & Right$(UserName, (Len(UserName) - InStr(1, UserName, " "))) & ".nsf"
Set Maildb = Session.GETDATABASE("", "")
If Maildb.IsOpen = True Then
Else
Maildb.OpenMail
End If

' Create New Mail and Address Title Handlers
Set MailDoc = Maildb.CreateDocument
MailDoc.Form = "Memo"
' Select range of e-mail addresses
'ccRecipient = Sheets("EmailSheet").Range("B2").Value
' Or send to a signle address
MailDoc.Sendto = "bob@ibm.com"
MailDoc.CopyTo = ccRecipient
' Subject & Body stored in a**worksheet
'MailDoc.Subject = Sheets("EmailSheet").Range("C2").Value
' MailDoc.Body = Sheets("EmailSheet").Range("ENTER CELL OF BODY").Value
' These can be entered here manually instead
MailDoc.Subject = "Check this out!"
MailDoc.body = "Cool huh?"

' Select Workbook to Attach to E-Mail
MailDoc.SaveMessageOnSend = True
'MsgBox ActiveWorkbook.FullName
attachment1 = "C:\test.xls"
If attachment1 <> "" Then
On Error Resume Next
Set AttachME = MailDoc.CREATERICHTEXTITEM("attachment1")
Set EmbedObj1 = AttachME.EmbedObject(1454, "", attachment1)
On Error Resume Next
End If

attachment2 = "c:\test.bat"
If attachment2 <> "" Then
On Error Resume Next
Set AttachME = MailDoc.CREATERICHTEXTITEM("attachment2")
Set EmbedObj1 = AttachME.EmbedObject(1454, "", attachment2)
On Error Resume Next
End If

'Displays email message without sending; user needs to click Send
Set workspace = CreateObject("Notes.NotesUIWorkspace")
Call workspace.EditDocument(True, MailDoc).GOTOFIELD("Body")


Set Maildb = Nothing
Set MailDoc = Nothing
Set AttachME = Nothing
Set Session = Nothing
Set EmbedObj1 = Nothing

.ScreenUpdating = True
.DisplayAlerts = True
End With

errorhandler1:

Set Maildb = Nothing
Set MailDoc = Nothing
Set AttachME = Nothing
Set Session = Nothing
Set EmbedObj1 = Nothing

End Sub

Open in new window


The problem is the body text is inserting directly after the Lotus Notes signature. I know, why not disable the signature in Lotus Notes. The problem is, this is being sent from a group box and I cannot disable it for all users. So my thought is I need some code that will eithe empty the body text (delete the signature) and then I can create the signature for the email directly in VBA. Or can I move the bodytext above the signature from within VBA?

Thank you in advance for your time and effort,
Josh
Avatar of jdpjtp910
jdpjtp910
Flag of United States of America image

ASKER

As a side note, can you open a stationery from VBA and attach files to it?
Instead of this line:

    Call workspace.EditDocument(True, MailDoc).GOTOFIELD("Body")

try this (to empty the contents of the body field):

    Dim notesUIDoc As Object
    Set notesUIDoc = workspace.EditDocument(True, MailDoc)
    Call notesUIDoc.GOTOFIELD("Body")
    Call notesUIDoc.FieldClear( )


To preserve the signature you can play with NotesUIDocument's SelectAll, Copy and Paste methods:
http://publib.boulder.ibm.com/infocenter/domhelp/v8r0/topic/com.ibm.designer.domino.main.doc/H_NOTESUIDOCUMENT_CLASS.html
mbonaci,

I tried your suggestion. It did not work. It still has the signature and then my word TEST next to it. It did however clear out my send to field and placed the cursor there instead of the body???
Hmm, strange.

Try to clear the body field with this:
Call notesUIDoc.FieldClear( "Body" )

FieldClear without argument clears the current field.
CORRECTION - The cursor is in the body text. Sorry still waking up :). But still, that piece of code will remove the subject text, not the body text.
Mbonaci,

The later post worked like a charm: Call notesUIDoc.FieldClear("Body")

Now, how can I add my text back into the body after that code? I tried a simple MailDoc.body="test" but it didnt work. So after we clear the body, how do I add text to it?
ASKER CERTIFIED SOLUTION
Avatar of mbonaci
mbonaci
Flag of Croatia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
THANK YOU!!! You rock. I have been looking for this forever! I always heard good things about this site, but I am glad I joined!

Thanks again! Look forward to more answers!