1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
| Sub SendNotesMail()
'Macro d'envoi automatique d'un onglet via Lotus Note:
Dim Retour As Integer
Retour = MsgBox("Vous allez transmettre l'onglet par mail. Assurez vous d'avoir Lotus Notes ouvert. Voulez vous continuez?", vbYesNo + vbQuestion + vbDefaultButton2, "ATTENTION")
If Retour = vbNo Then
Exit Sub
Else
On Error Resume Next
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)
Dim j As String
Dim dest As String
Dim monTab() As String
Dim nomfichier As String, nomfichier2 As String
'''''''''''''''''''''''''''''''''''''Envoi de l'onglet "Feuil2"
dest = Sheets("Feuil1").Cells(1, 1).Value
'Les adresses mail des correspondants sont entré?? cellule A1 de la Feuil1 sép?é p? u? v?ule.
Set Session = CreateObject("Notes.NotesSession")
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
'Ici on transforme la variable dest de type string contenant les adresses en tableau via la fonction split
monTab = Split(dest, ",")
Dim ccRecipent As String
'Set up the new mail document
Set MailDoc = Maildb.CreateDocument
MailDoc.Form = "Memo"
MailDoc.Subject = "Demande d'avoir aux usines "
MailDoc.Body = "Bonjour," & vbCrLf & vbCrLf & vbCrLf & "Veuillez trouver ci-joint," & vbCrLf & vbCrLf & " Les dates courtes de ce jour." & vbCrLf & vbCrLf & vbCrLf & vbCrLf & " Cordialement ," & vbCrLf & vbCrLf & "Ce message est généré automatiquement."
MailDoc.SaveMessageOnSend = SaveIt
Sheets("Feuil1").Copy
ChDir "U:\Logistique\Testttt"
nomfichier = "U:\Logistique\Testttt\" & "test " & ".xls"
nomfichier2 = "test " & ".xls"
ActiveWorkbook.SaveAs Filename:= _
nomfichier, FileFormat:= _
xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False _
, CreateBackup:=False
Attachment = Workbooks(nomfichier2).FullName
If Attachment <> "" Then
Set AttachME = MailDoc.CREATERICHTEXTITEM("Attachment")
Set EmbedObj = AttachME.EMBEDOBJECT(1454, "", Attachment, "Attachment")
MailDoc.CREATERICHTEXTITEM ("Attachment")
End If
'Send the document
MailDoc.PostedDate = Now()
MailDoc.Send 0, monTab()
'Clean Up
Set Maildb = Nothing
Set MailDoc = Nothing
Set AttachME = Nothing
Set Session = Nothing
Set EmbedObj = Nothing
End If
'Supression du fichier contenant le contenu de l'onglet "Feuil2"
Workbooks(nomfichier2).Close
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFile(nomfichier)
End If
End Sub |
Partager