Envoi feuille Excel par mail en PJ via lotus
j
Bonjour a tous
Mon probleme est dans le titre
Je cherche a envoyer une feuille d'un classeur par mail en PJ via Lotus
Actuellement j'arrive a envoyer le mail mais j'arrive pas a mettre la PJ
Voici mon code
Merci d'avance
Sub SendNotesMail()
'Set up the objects required for Automation into lotus notes
Dim Maildb As NotesDatabase 'The mail database
Dim MailDoc As Object 'The mail document itself
Dim oSession As NotesSession
Dim dbDirectory As NotesDbDirectory
Dim objNotesField As Object
On Error GoTo ErrHandle
'Démarre une session de notes
Set oSession = New NotesSession
'La ligne suivante ne marche qu'avec les versions 5.x et 6.x , c'est l'injection du mot de passe
oSession.Initialize ("XXXXXX")
'Ouvre la base mail en utilisant le serveur par défaut
Set dbDirectory = oSession.GetDbDirectory("XX/XX/XX")
Set Maildb = dbDirectory.OpenMailDatabase
'Création du formulaire d'envoi de mail
Set MailDoc = Maildb.CreateDocument()
MailDoc.AppendItemValue "Subject", "Formulaire FOR0015"
MailDoc.AppendItemValue "SendTo", "XX@XX.fr"
Set objNotesField = MailDoc.CreateRichTextItem("Body")
With objNotesField
.AppendText "Bonjour," & Chr(13) & Chr(10) & Chr(13) & Chr(10) & Chr(13) & Chr(10)
.AppendText "Voici le formulaire FOR0015" & Chr(13) & Chr(10) & Chr(13) & Chr(10)
.AppendText "Cordialement"
End With
'Envoi le document
If SaveIt = True Then
MailDoc.SaveMessageOnSend = SaveIt 'si à True, Lotus sauvegarde le mail envoyé
End If
Call MailDoc.Send(False)
GoTo ExitHandle
ErrHandle:
MsgBox Err.Description
ExitHandle:
'Vidage mémoire
Set Maildb = Nothing
Set MailDoc = Nothing
Set oSession = Nothing
Set dbDirectory = Nothing
Set objNotesField = Nothing
End Subj
Entre temps j'ai trouvé une solution qui marche nikel
Voici le code :
Option Explicit
Const EMBED_ATTACHMENT As Long = 1454
Const stPath As String = "C:\XX\XX\"
Const stSubject As String = "XXXX"
Const vaMsg As Variant = "Bonjour," & vbCrLf & vbCrLf & vbCrLf & "Voici le formulaire" & vbCrLf & vbCrLf & "Cordialement"
Const vaCopyTo As Variant = "name@mail.com"
Sub Send_Active_Sheet()
Dim stFileName As String
Dim vaRecipients As Variant
Dim noSession As Object
Dim noDatabase As Object
Dim noDocument As Object
Dim noEmbedObject As Object
Dim noAttachment As Object
Dim stAttachment As String
'Copy the active sheet to a new temporarily workbook.
With ActiveSheet
.Copy
stFileName = .Range("G7").Value
End With
stAttachment = stPath & "\" & stFileName & ".xls"
'Save and close the temporarily workbook.
With ActiveWorkbook
.SaveAs stAttachment
.Close
End With
'Create the list of recipients.
vaRecipients = VBA.Array("XX@XX.fr")
'Instantiate the Lotus Notes COM's Objects.
Set noSession = CreateObject("Notes.NotesSession")
Set noDatabase = noSession.GetDatabase("", "")
'If Lotus Notes is not open then open the mail-part of it.
If noDatabase.IsOpen = False Then noDatabase.OPENMAIL
'Create the e-mail and the attachment.
Set noDocument = noDatabase.CreateDocument
Set noAttachment = noDocument.CreateRichTextItem("stAttachment")
Set noEmbedObject = noAttachment.EmbedObject(EMBED_ATTACHMENT, "", stAttachment)
'Add values to the created e-mail main properties.
With noDocument
.Form = "Memo"
.SendTo = vaRecipients
'.CopyTo = vaCopyTo
.Subject = stSubject
.Body = vaMsg
.SaveMessageOnSend = True
.PostedDate = Now()
.Send 0, vaRecipients
End With
'Delete the temporarily workbook.
Kill stAttachment
'Release objects from memory.
Set noEmbedObject = Nothing
Set noAttachment = Nothing
Set noDocument = Nothing
Set noDatabase = Nothing
Set noSession = Nothing
MsgBox "Email crée et envoyé avec succès", vbInformation
End Sub