Hello, I'm French so I apologize if i make any English mistakes!
Here my problem:
I'm looking to send a message through Lotus Notes V6.5 using a Button in a Userform.
I would like to open it in Lotus Notes before sending in order to modify it if needed
I found 2 different codes to solve my problem but I can't reach exactly what I need.
First Code:
Private Sub CommandButton1_Click()
'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 EmbedObj As Object 'The embedded object (Attachment)
If UserFormEMail.ListBox2.ListCount = 0 Then MsgBox "No Hay Proyectos Seleccionados Para Mensaje"
If UserFormEMail.ListBox2.ListCount = 0 Then Exit Sub
'Start a session to notes
Set Session = CreateObject("Notes.NotesSession")
'Get the sessions username and then calculate the mail file name
'You may or may not need this as for MailDBname with some systems you
'can pass an empty string
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
MailDoc.Form = "Memo"
MailDoc.Sendto = "[email protected]" 'UserFormEMail.TextBox9.Value
MailDoc.CopyTo = ""
MailDoc.Subject = "essaie d'envoi adresse differentes"
' Construction du corps du message
Set objNotesField = MailDoc.CreateRichTextItem("Body")
With objNotesField
.AppendText "Buenos Dias,"
.AddNewline 2
.AppendText "Usted podrìa enviarme el Order Entry Form del (de los) proyecto(s) sigienete(s):"
.AddNewline 2
For i = 0 To UserFormEMail.ListBox2.ListCount - 1
.AppendText UserFormEMail.ListBox2.List(i) & " --- " & UserFormEMail.ListBox3.List(i)
.AddNewline 2
Next i
.AddNewline 2
.AppendText "Un saludo Cordial"
.AddNewline 1
.AppendText "Bruno Antoniol"
.AddNewline 3
End With
MailDoc.SaveMessageOnSend = True
'Set up the embedded object and attachment and attach it
'Send the document
MailDoc.PostedDate = Now() 'Gets the mail to appear in the sent items folder
MailDoc.Send (False)
'Clean Up
Set Maildb = Nothing
Set MailDoc = Nothing
Set AttachME = Nothing
Set Session = Nothing
Set EmbedObj = Nothing
End Sub
With that code, my problem is that the message is sent directly without the possibility of modifying it on Lotus Notes
And second code:
'---------- API -----------
'pour faire passer au premier plan
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hWnd As Long) As Long
'pour ouvrir la fenêtre
Private Declare Function ShowWindow Lib "user32" (ByVal hWnd As Long, _
ByVal nCmdShow As Long) As Long
'pour vérifier si Lotus est ouvert
Private Declare Function FindWindow Lib "user32" Alias _
"FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Dim sSrvr As String 'Le serveur de mail de l'utilisateur courant
Dim MailDbName As String 'Le nom de la base mail de l'utilisateur courant
Dim UserName As String 'Le nom de l'utilisateur courant
Dim retVal As Variant 'La valeur de retour de la fonction
'---------------- fonction ouverture de session Notes -----------
Function CreateNotesSession() As Boolean
Const notesclass$ = "NOTES"
Const SW_SHOWMAXIMIZED = 3 'plein ecran
Const SW_SHOWMMINIZED = 2 'reduire
Const SW_SHOWWINDOW = 1 'fenetre
Const SW_SHOW = 5
Dim Lotus_Session As Object
Dim rc&
Dim lotusWindow&
' lotusWindow = FindWindow(notesclass, vbNullString)
' sSrvr = Lotus_Session.GETENVIRONMENTSTRING("MailServer", True)
' MailDbName = Lotus_Session.GETENVIRONMENTSTRING("MailFile", True)
' UserName = Lotus_Session.UserName
' DoEvents
'Ouverture de Lotus Notes
'Mettre votre chemin d'accès pour notes.exe et notes.ini'
'retVal = Shell("C:\Program Files\lotus\notes\notes.exe =C:\Program Files\lotus\notes\notes.ini", vbMaximizedFocus)
'verifier que Lotus est bien ouvert (recupere le handle)
lotusWindow = FindWindow(notesclass, vbNullString)
If lotusWindow <> 0 Then
rc = ShowWindow(lotusWindow, SW_SHOW)
rc = SetForegroundWindow(lotusWindow)
CreateNotesSession = True
Else
CreateNotesSession = False
End If
End Function
Private Sub CommandButton1_Click()
Const EMBED_ATTACHMENT As Integer = 1454
Const EMBED_OBJECT As Integer = 1453
Const EMBED_OBJECTLINK As Integer = 1452
Dim s As Object ' use back end classes to obtain mail database name
Dim db As Object '
Dim doc As Object ' front end document
Dim beDoc As Object ' back end document
Dim workspace As Object ' use front end classes to display to user
Dim bodypart As Object '
Dim bodyAtt As Object '
Dim lbsession As Boolean
lbsession = CreateNotesSession
If lbsession Then
'cree la session Lotus Notes
Set s = CreateObject("Notes.Notessession")
'se connecte a sa database
Set db = s.getDatabase(sSrvr, MailDbName)
If db.IsOpen = True Then
'database deja ouvert
Else
Call db.Openmail
End If
'cree un document memo
Set beDoc = db.CreateDocument
beDoc.Form = "Memo"
'construction du mail
Set bodypart = beDoc.CreateRichTextItem("Body")
'beDoc.From = "Moi" 'inutile
beDoc.SendTo = UserFormEMail.TextBox9.Value
beDoc.CopyTo = CCToAdr
beDoc.BlindCopyTo = BCCToAdr
beDoc.Subject = UserFormEMail.TextBox10.Value & " Pendiente"
With bodypart
.AppendText "Buenos Dias,"
.AddNewline 2
.AppendText "Usted podrìa enviarme el Order Entry Form del (de los) proyecto(s) sigienete(s):"
.AddNewline 2
For i = 0 To UserFormEMail.ListBox2.ListCount - 1
.AppendText UserFormEMail.ListBox2.List(i) & " --- " & UserFormEMail.ListBox3.List(i)
.AddNewline 2
Next i
.AddNewline 2
.AppendText "Un saludo Cordial"
.AddNewline 1
.AppendText "Bruno Antoniol"
.AddNewline 3
End With
'-----------------------------------------
'Remarque s'il y a des destinataires multiples, il suffit de mettre un tableau
'd'e-mail dans SendTo (CopyTo,BlindCopyTo)
'exemple :
'Dim recip(25) as variant
'recip(0) = "emailaddress1"
'recip(1) = "emailaddress2" e.t.c
'beDoc.sendto = recip
'----------------------------------------
' documents joint 1
If Len(Attach1) > 0 Then
If Len(dir(Attach1)) > 0 Then
Set bodyAtt = bodypart.EmbedObject(EMBED_ATTACHMENT, "", Attach1, dir(Attach1))
End If
End If
' documents joint 2
If Len(Attach2) > 0 Then
If Len(dir(Attach2)) > 0 Then
Call bodyAtt.EmbedObject(EMBED_ATTACHMENT, "", Attach2, dir(Attach2))
End If
End If
'Affichage du mail dans Lotus Notes
Set workspace = CreateObject("Notes.NotesUIWorkspace")
Call workspace.EditDocument(True, beDoc).FieldSetText("Body", "CORPS DE MESSAGE")
Set s = Nothing
Else
MsgBox "Open Lotus Notes Before !"
End If
End Sub
With that code, it opens well the message before sending, but my problem is that I don't know how to write a message with that syntax:
Hello Mr. *
ComboBox1(Name)*,
I'm writing you concerning projects:: *
ListBox1(Nº of project)*
To ask you the following information: *(if
CheckBox1=true then
CheckBox1.Caption)*
Please, send it to me before that date: *
TextBox2 (date)*
Best reguards,
Bruno
Do you have any solution to modify one of those codes?
Thanks in advance. Don’t hesitate to ask me if you don’t understand me!
Bruno
Bookmarks