D'avance merci pour les réponses
Cordialement
René
Tu trouveras ci-dessous copie d'un post de F. SIGONNEAU du 10avril 2002 qui
devrait t'aider... Attention le post est très long !!!
Bon courage,
--
Fripouillot
===== DEBUT DE COPIE =====
Bonsoir,
Ci-joint deux modules de code récupérés sur le forum anglophone. Je n'ai
jamais
utilisé Lotus Notes, alors merci de me faire savoir si ces bouts de code
t'ont
été de quelque utilité pour satisfaire ta "petite envie" :-))
FS
--
Frédéric Sigonneau [né un sans-culottide]
Gestions de temps, VBA pour Excel :
http://perso.wanadoo.fr/frederic.sigonneau
'===============module de code n°1
'envoyer un classeur Excel en pièce jointe avec Lotus Notes
Sub Sendmail()
'Kim Zethsen, mpep
Dim AktuelSide As String
Dim Aktuelcelle As Range
Dim myNotes As Object
Dim myDB As Object
Dim myDoc As Object
Dim myItem As Object
Dim recipient As String
'The range "prognose" is copied to an existing xls file with some special
'formatting then the formatted file is send via notes
Sheets("Sheet1").Range("prognose").Copy
Workbooks.Open Filename:="p:\prognose.xls"
Sheets("Sheet1").Range("c3").Select
Selection.PasteSpecial Paste:=xlValues
Application.CutCopyMode = False
Sheets("Sheet1").Range("a1").Select
ActiveWorkbook.Save
ActiveWindow.Close
'here comes Notes
recipient = [recipient] ' range("recipient") is variable to the email
adress
'or maybe you would have to use: recipient=range("Recipient")
Set myNotes = CreateObject("Notes.NotesSession")
Set myDB = myNotes.GETDATABASE("", "")
myDB.OPENMAIL
Set myDoc = myDB.CREATEDOCUMENT
Set myItem = myDoc.APPENDITEMVALUE("Subject", "Prognose for " + [dato])
'range dato is range variable for date
Set myItem = myDoc.APPENDITEMVALUE("SendTo", recipient)
Set myItem = myDoc.CREATERICHTEXTITEM("Body")
With myItem
.ADDNEWLINE 2
.APPENDTEXT "Best regards"
.ADDNEWLINE 3
End With
Call myItem.EmbedObject(1454, "", "p:\prognose.xls")
Call myDoc.SEND(False, recipient)
End Sub
'=================================
'===============module de code n°2
'envoyer des messages électroniques avec Lotus Notes
Sub testSendMail()
Dim bOK As Boolean
bOK = sendNotesMail(Range("Subject"), Range("Attachment"), _
Range("Recipient"), Range("BodyText"), Range("SaveIt"))
MsgBox "sent : " & CStr(bOK)
End Sub
Function sendNotesMail(Subject As String, attachment As String, _
recipient As String, bodytext As String, SaveIt As Boolean) As Boolean
Dim Maildb As Object
Dim UserName As String
Dim MailDbName As String
Dim MailDoc As Object
Dim AttachME As Object
Dim session As Object
Dim EmbedObj As Object
On Error GoTo err_SendNotesMail
'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 = Mid$(UserName, 4, 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 = recipient
MailDoc.Subject = Subject
MailDoc.Body = bodytext
MailDoc.SaveMessageOnSend = SaveIt
'Set up the embedded object and attachment and attach it
If attachment <> "" And Dir(attachment) <> "" Then
Set AttachME = MailDoc.CreateRichTextItem("Attachment")
Set EmbedObj = AttachME.EmbedObject(1454, "", attachment, "Attachment")
'MailDoc.CREATERICHTEXTITEM ("Attachment")
End If
'Send the document
MailDoc.Send 0, recipient
Maildb.Close
'Clean Up
Set Maildb = Nothing
Set MailDoc = Nothing
Set AttachME = Nothing
Set session = Nothing
Set EmbedObj = Nothing
sendNotesMail = True
end_SendNotesMail:
Exit Function
err_SendNotesMail:
Select Case Err.Number
Case 429:
MsgBox "Error: " & vbCrLf & Err.Description & vbCrLf & _
"Possible cause : " & vbCrLf & "Lotus Notes not installed", _
vbCritical, "Error while initializing LotusNotes"
Case Else:
MsgBox Err.Description & Err.Number, vbCritical, "Error Lotus Notes
Mail"
End Select
Resume end_SendNotesMail
End Function
Sub SendLotusNote()
' be sure to reference the Lotus Domino Objects, domobj.tlb
Dim objNotesSession As Object
Dim objNotesDatabase As Object
Dim objNotesDocument As Object
Dim objAttachment As Object
Dim objRichText As Object
Dim FullPath As String
Dim FileName As String
Dim Msg As String
Const EMBED_ATTACHMENT = 1454
Set objNotesSession = CreateObject("Notes.Notessession")
Set objNotesDatabase = objNotesSession.GETDATABASE("", "")
'rétablir cette ligne avec la référence à domobj.tlb ????
' Call objNotesDatabase.OpenMail default mail database
If objNotesDatabase.IsOpen = False Then
MsgBox "Cannot connect to Lotus Notes."
Exit Sub
End If
Set objNotesDocument = objNotesDatabase.CreateDocument
Call objNotesDocument.ReplaceItemValue("Form", "Memo")
Do ' prompt user for file name and location
FullPath = Application.GetSaveAsFilename
Loop Until FullPath <> False
' save to new loc; Lotus only sends last-saved copy
ActiveWorkbook.SaveAs FullPath
FileName = ActiveWorkbook.Name
' assemble message
Set objRichText = objNotesDocument.CreateRichTextItem("Body")
Set objAttachment = objRichText.EmbedObject(EMBED_ATTACHMENT, "", _
FullPath, FileName)
Msg = "Lotus Note sent from " & objNotesSession.CommonUserName
With objNotesDocument
.Subject = "Excel Lotus Note!"
.Body = Msg
.sendTo = "lotus.mailbox"
.SaveMessageOnSend = True ' save in Sent folder
.Send (False)
End With
Set objNotesSession = Nothing
Set objNotesDatabase = Nothing
Set objNotesDocument = Nothing
Set objAttachment = Nothing
Set objRichText = Nothing
MsgBox "Your Lotus Notes message was successfully sent"
ActiveWorkbook.Close
End Sub
Sub EMail()
'You will also need to reference 'Notes32.tlb' in your project.
Dim session As Object
Dim db As Object
Dim doc As Object
Set session = CreateObject("Notes.NotesSession")
Set db = session.GETDATABASE("Your Domino Server", "Your Mail Database")
Set doc = db.CreateDocument()
doc.Form = "Memo"
doc.Subject = "VB App Test " & Now()
doc.Body = "VB App Test. Sending Notes memos via VB"
doc.sendTo = "y...@yourcompany.com"
Call doc.Send(False, "")
Set doc = Nothing
Set db = Nothing
Set session = Nothing
End Sub
Sub mailsend2()
Dim Data As Variant
Dim mailcount As Integer
Dim s As Object, db As Object, doc As Object
Data = Range("A1:B6").Value 'defines the source data in two cols on
active
Sheet
Set s = CreateObject("Notes.NotesSession")
Set db = s.GETDATABASE("", "mail\username.nsf")
Set doc = db.CreateDocument()
For mailcount = 1 To 6
doc.Form = "Memo"
doc.sendTo = Data(mailcount, 1)
doc.Subject = Data(Str(mailcount), 2)
doc.Body = "Rats Trousers" & " " & Data(Str(mailcount), 2)
Call doc.Send(False)
Next
Set s = Nothing
Set db = Nothing
Set doc = Nothing
End Sub
===== FIN DE COPIE =====
"Gesbert rené" <rges...@netcourrier.com> a écrit dans le message de news:
93c301c25677$31651400$9de62ecf@tkmsftngxs01...
Tu pourrais peut-être essayer le code ci-dessous, récupéré sur le forum
anglophone.
FS
--
Frédéric Sigonneau [né un sans-culottide]
courrier : frederic....@laposte.net
Gestions de temps, VBA pour Excel :
http://perso.wanadoo.fr/frederic.sigonneau
'==========================
'here comes Notes
End Sub
'=====================
Gesbert rené a écrit :
Merci du relais ! J'aurais du vérifier les réponses avant de poster, d'autant
que j'ai été moins généreux aujourd'hui qu'en avril dernier :(
FS
--
Frédéric Sigonneau [né un sans-culottide]
courrier : frederic....@laposte.net
Gestions de temps, VBA pour Excel :
http://perso.wanadoo.fr/frederic.sigonneau
Fripouillot a écrit :