Attacher tous les documents dun fichier à un mail - VB/VBA/VBS - Programmation
Marsh Posté le 15-05-2005 à 10:19:40
Comment envoyer une feuille dans un message en VBA?(testé avec Excel 2003)
j'ai trouvé ce petit programme sur vbafrance, je l'ai testé il marche
Sub MailFeuilleOE()
Dim Dest, Sujt, Msg As String
Dim RepName
ActiveSheet.Copy
ActiveWorkbook.SaveAs Filename:="C:\temp\test.xls"
RepName = "C:\temp\test.xls"
Dest = "dj@free.fr"
Sujt = "Test d'envoi d'une feuille avec Excel"
Msg = "Bonjour, Excel vous envoie une feuille avec OE"
Shell "C:\Program Files\Outlook Express\msimn.exe " & _
"/mailurl:mailto:" & Dest & "?subject=" & Sujt & "&Body=" & Msg & ""
SendKeys "%I" & "p" & RepName & "~" & "%s"
ActiveWorkbook.Close
End Sub
Marsh Posté le 15-05-2005 à 10:32:06
oups,j'ai repondu trop vite, testé avec lotus 6.5.1, chez moi ça marche, au boulot il faut que lotus soit ouvert.
Private Sub CommandButton11_Click()
Dim Recipient(2) As Variant 'pour deux destinataires mais tu peux faire un tableau variable
Dim Attachment(3) As Variant 'pour 3 pièces jointes mais tu peux aussi faire un tableau variable
'
'Dim attachment As String
Dim BodyText As String
Dim SaveIt As Boolean
Dim Subject As String
'dim SendNotesMail(subject As String, Attachments As String, BodyText As String, SaveIt As Boolean)
Recipient(0) = "adresse1@free.fr"
Recipient(1) = "adresse2@free.fr"
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 databasename
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)
'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 = Recipient 'Envoi à tous les destinataires
MailDoc.Subject = Subject
MailDoc.body = BodyText
MailDoc.ReturnReceipt = "1"
MailDoc.SAVEMESSAGEONSEND = SaveIt
'Set up the embedded object and attachment and attach it
Attachment(0) = "c:\EnvoiMailLotus\test1.txt"
'txtFromEmailAddress
Attachment(1) = "c:\EnvoiMailLotus\test2.txt"
'txtFromEmailAddress
Attachment(2) = "c:\EnvoiMailLotus\test.xls"
'txtFromEmailAddress
'Les trois attachement sont les nom et chemins des fichiers à envoyer
For i = 0 To 2
If Attachment(i) <> "" Then
Set AttachME = MailDoc.CREATERICHTEXTITEM("Attachment(" & i & " )" )
Set EmbedObj = AttachME.EMBEDOBJECT(1454, "", Attachment(i), "Attachment(" & i & " )" )
'mailDoc.CREATERICHTEXTITEM ("Attachment(" & i & " )" )
End If
Next i
'Send the document
MailDoc.PostedDate = Now() 'Gets the mail to appear in the sent items folder
MailDoc.SEND 0, Recipient
'Clean Up
Set Maildb = Nothing
Set MailDoc = Nothing
Set AttachME = Nothing
Set Session = Nothing
Set EmbedObj = Nothing
End Sub
Marsh Posté le 09-05-2005 à 13:12:16
Bonjour,
Avec une macro, je voudrai attacher à un mail avec Lotus tous les documents dun fichier en pièces jointes.
Merci pour votre aide.