Mail aves pièce(s) jointe(s) sous lotus note

Bonjour à tous,

Mon problème est le suivant, après plusieurs heures de recherche sur internet et de test, je n'arrive toujours pas à joindre une pièce dans mon mail.

Voici le code:

Sub mail()
    Dim Session As Object
    Dim Dir As Object
    Dim Doc As Object
    Dim ObjNotesField As Object
    Dim Workspace As Object
    Dim EditDoc As Object

On Error GoTo TraiteErreur

    'Création de la session Notes
    Set Workspace = CreateObject("Notes.NotesUIWorkspace")
    Set Session = CreateObject("notes.NOTESSESSION")
    Set Dir = Session.GETDATABASE("", "")
    Call Dir.OPENMAIL

    'Creation d'un document
    Set Doc = Dir.CREATEDOCUMENT
    Doc.body = "This is the body."
    Doc.form = "Memo"
    Doc.Subject = "Sujet du mail"
    Doc.sendto = "Receiver@mail.com"
   ' Doc.AddAttachment ("U:\\test.txt") ???
  ' Call ObjNotesField.EMBEDOBJECT(1454, "", ????)
JE NE SAIS PAS COMMENT INSTANCIER ICI L OBJET JOINT

    'Affichage du mail dans Lotus Notes
    Set EditDoc = Workspace.EditDocument(True, Doc)

    Set Session = Nothing
    Set Dir = Nothing
    Set Doc = Nothing
    Set Workspace = Nothing
    Set EditDoc = Nothing

    Exit Sub

TraiteErreur:

    MsgBox "Problème de création du mail", vbCritical, "Error"

    Set Session = Nothing
    Set Dir = Nothing
    Set Doc = Nothing
    Set Workspace = Nothing
    Set EditDoc = Nothing

End Sub

Ce n'est malheureusement que le début de mon soucis .. Car je souhaite (après avoir déjà resolu ce soucis) optimiser le code pour joindre des fichier spécifique aux destinataires ... Mais nous verrons ça plus tard lol

Merci d'avance !

Cdt, arkhang !

On m'a aidé sur un autre forum. Résolu.

Ca aurait été bien de joindre la solution.

J'ai le même problème

Bonjour Gilles,

En espérant que je pourrais mieux t'aider, qu'on ne me l'a fait ici, voilà le code :

Const EMBED_ATTACHMENT As Long = 1454
Const stPath As String = "D:\Documents and Settings\user\TravauxApp\Macros\EnvoiMails"
 Sub Mail()

  Dim MaDate As String
  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
  Dim vaMsg As Variant
  Dim StrSignature As Variant
  Dim stSubject As String

  On Error GoTo TraiteErreur

  stSubject = "test le" & " " & Date$
  MaDate = Date

  vaMsg = "Bonjour, " & vbCrLf & vbCrLf & vbCrLf & _
  vbCrLf & vbCrLf & vbCrLf & vbCrLf & vbCrLf & vbCrLf & vbCrLf _
  & "SIGNATURE A RAJOUTER"

  stFileName = "test"
  stAttachment = stPath & "\" & stFileName & ".txt"

  'test de l'existance de la PJ
  If Dir(stAttachment) = "" Then GoTo TraitePJ

  vaRecipients = "reciever@yahoo.fr"
  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
        .Subject = stSubject
        .body = vaMsg
        .SaveMessageOnSend = True
        .PostedDate = Now()
    End With

    'Affichage du mail dans Lotus Notes.
    Dim Workspace
    Set Workspace = CreateObject("Notes.NotesUIWorkspace")
    Call Workspace.EditDocument(True, noDocument).FieldSetText("Body", vaMsg)

  'Release objects from memory.
  Set noEmbedObject = Nothing
  Set noAttachment = Nothing
  Set noDocument = Nothing
  Set noDatabase = Nothing
  Set noSession = Nothing

  Exit Sub

TraitePJ:

    MsgBox "Un problème est survenu lors de l'insertion de la pièce jointe", vbCritical, "Error"

    Set noEmbedObject = Nothing
    Set noAttachment = Nothing
    Set noDocument = Nothing
    Set noDatabase = Nothing
    Set noSession = Nothing

    Exit Sub

TraiteErreur:

    MsgBox "Un problème est survenu lors de la création du mail", vbCritical, "Error"

    Set noEmbedObject = Nothing
    Set noAttachment = Nothing
    Set noDocument = Nothing
    Set noDatabase = Nothing
    Set noSession = Nothing

End Sub

Ce code fonctionne pour l'envoie d'un fichier, avec l'emplacement définit comme constant (stPath).

En espérant que ça pourra t'aider

Cdt, arkhang.

Merci.

J'ai repris ton code.

Et çà fonctionne.

J'ai juste rajouté, la création de la feuille active sous PDF à l'emplacement même ou il y a le fichier excel.

Dans mon cas de figure, c'était réception du fichier excel sous lotus notes, donc sous un dossier "TEMP" si l'utilisateur ne l'enregistre pas manuellement dans un dossier de son choix.

Du coup pas besoin de pointer le fichier source pour récupérer la pièce jointe en PDF.

Bonjour,

j'ai utilisé le même code, mais cela me met un message d'erreur: "Erreur lors la création du mail". Je pense que ça vient du Const stPath As String = "D:\Documents and Settings\user\TravauxApp\Macros\EnvoiMails".Pouvez-vous m'aider?

Merci

Bonsoir Alex,

As tu recrée la même arborescence que moi ?

Si nan, c'est normal que ça ne marche pas, il faut l'adapter à l'emplacement de ton fichier en fait

Si tu as d'autres questions, n'hésite pas !

Le code ci-dessous te permettra d'envoyer le classeur excel en pièce jointe sous lotus note

Const EMBED_ATTACHMENT As Long = 1454

Const stPath As String = ""

Sub EnvoiEmailXLS()

If MsgBox("Avez vous pensé à renommer ce classeur Excel ?", vbQuestion + vbYesNo, "Veuillez répondre par OUI ou NON ? ...") = vbYes Then

ActiveWorkbook.Save

Else

Call enregistrersous

ActiveWorkbook.Save

End If

MsgBox ("Ce fichier Excel a été transmis à LOTUS NOTE pour faire suivre.")

Dim MaDate As String

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

Dim vaMsg As Variant

Dim StrSignature As Variant

Dim stSubject As String

On Error GoTo TraiteErreur

stSubject = ""

MaDate = Date

vaMsg = "Bonjour, " & vbCrLf & vbCrLf & vbCrLf & _

vbCrLf & vbCrLf & vbCrLf & vbCrLf _

& "Bonne réception." & vbCrLf _

& "Cordialement."

stFileName = "test"

stAttachment = ActiveWorkbook.Path & "\" & ActiveWorkbook.Name

'test de l'existance de la PJ

If Dir(stAttachment) = "" Then GoTo TraitePJ

vaRecipients = ""

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

.Subject = stSubject

.Body = vaMsg

.SAVEMESSAGEONSEND = True

.PostedDate = Now()

End With

'Affichage du mail dans Lotus Notes.

Dim Workspace

Set Workspace = CreateObject("Notes.NotesUIWorkspace")

Call Workspace.EditDocument(True, noDocument).FieldSetText("Body", vaMsg)

'Release objects from memory.

Set noEmbedObject = Nothing

Set noAttachment = Nothing

Set noDocument = Nothing

Set noDatabase = Nothing

Set noSession = Nothing

Exit Sub

TraitePJ:

MsgBox "Un problème est survenu lors de l'insertion de la pièce jointe", vbCritical, "Error"

Set noEmbedObject = Nothing

Set noAttachment = Nothing

Set noDocument = Nothing

Set noDatabase = Nothing

Set noSession = Nothing

Exit Sub

TraiteErreur:

MsgBox "Un problème est survenu lors de la création du mail", vbCritical, "Error"

Set noEmbedObject = Nothing

Set noAttachment = Nothing

Set noDocument = Nothing

Set noDatabase = Nothing

Set noSession = Nothing

End Sub

Sub enregistrersous()

Excel.Application.Dialogs(xlDialogSaveAs).Show

End Sub

Bonsoir Arkhang,

Non je ne l'ai pas fait et je ne peux pas, je suis sur une station au travail. Les disques sont sur réseau au boulot. Est-il quand même possible de le faire? L'emplacement de mon fichier , c'est à dire: je mets le chemin d'accès + le nom du fichier derrière.xls? Car j'ai l'impression que le chemin d'accès dans ton code mène à un dossier et non à un fichier excel.

Bonsoir Gilles,

Je vais l'essayer dès demain au travail. J'espère que ça ira!:) Merci

Reprend l'exemple de Gilles qui est bien plus complet que ce vieux code

Et oui ça devrait marcher aussi bien sur du réseau.

Re bonjour,

Le code de Gilles ne fonctionne pas, ça me demande de l'enregistrer sous, mais ensuite il ne se passe rien...

Help me please...

Je t'envoi le fichier ce soir.

Ok merci Gilles. Bonne journée,

Voir le fichier en pièce jointe.

Il est en xlsm pour info

Je te remercie Gilles. Je vais essayer le code vendredi au boulot et je vais voir ce que le code va donner sur mon fichier.

Saurais-tu comment transcrire en code l'intégration de deux feuilles d'un même fichier dans l'envoie du mail? Est-ce qu'il suffit de recopier le code qui sélectionne la première feuille l'un derrière l'autre?

Car mon fichier comporte deux feuilles.

Bonne soirée

Rechercher des sujets similaires à "mail aves piece jointe lotus note"