VBA Affichage de Mail avant envoi LOTUS Notes

brunounours Messages postés 3 Statut Membre -  
senecartour Messages postés 391 Statut Membre -
Bonjour,

J'aimerai modifier le code suivant:
Private Sub CommandButton1_Click()


 
'Set up the objects required for Automation into lotus notes
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)
 
 
If UserFormEMail.ListBox2.ListCount = 0 Then MsgBox "No Hay Proyectos Seleccionados Para Mensaje"
If UserFormEMail.ListBox2.ListCount = 0 Then Exit Sub
 
'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 = "CST_BAntoniol@xxxx.com" 'UserFormEMail.TextBox9.Value
MailDoc.CopyTo = ""
MailDoc.Subject = "essaie d'envoi adresse differentes"
' Construction du corps du message
Set objNotesField = MailDoc.CreateRichTextItem("Body")
With objNotesField
.AppendText "Buenos Dias,"
.AddNewline 2
.AppendText "Usted podrìa enviarme el Order Entry Form del (de los) proyecto(s) sigienete(s):"
.AddNewline 2
For i = 0 To UserFormEMail.ListBox2.ListCount - 1
.AppendText UserFormEMail.ListBox2.List(i) & " --- " & UserFormEMail.ListBox3.List(i)
.AddNewline 2
Next i
.AddNewline 2
.AppendText "Un saludo Cordial"
.AddNewline 1
.AppendText "Bruno Antoniol"
.AddNewline 3
End With


MailDoc.SaveMessageOnSend = True
'Set up the embedded object and attachment and attach it

 
'Send the document
MailDoc.PostedDate = Now() 'Gets the mail to appear in the sent items folder
MailDoc.Send (False)
 
'Clean Up
Set Maildb = Nothing
Set MailDoc = Nothing
Set AttachME = Nothing
Set Session = Nothing
Set EmbedObj = Nothing



de telle sorte que le mail ne soit pas envoyé directement mais qu'il s'affiche dans Lotus Note (V6.5) pour ainsi pouvoir le modifier si besoin est.

Help!

Bruno

2 réponses

  1. brunounours Messages postés 3 Statut Membre
     
    Autre variante pour résoudre ce problème:

    Voila j'ai un autre code qui lui ouvre bien le message dans Lotus note avant de l'envoyer.

    Cette solution me conviendrai excepté le corps du message que je n'arrive pas à mettre sous forme:

    Bonjour Monsieur *TextBox1(Prénom)* *ComboBox1(Nom)*,

    Je vous écrit concernant les projets: *ListBox1(Nº de projet)*
    Afin que vous apportiez les précisions suivante: *(if CheckBox1=true then CheckBox1.Caption)* avant la date suivante: *TextBox2 (date)*

    Meilleures Salutations. Bruno


    Bientot 8 heure a chercher!!

    Je commence à m'arracher les cheveux! Merci de votre aide!

    Bruno

    Voici le code que j'ai

    '---------- API -----------
    'pour faire passer au premier plan
    Private Declare Function SetForegroundWindow Lib "user32" (ByVal hWnd As Long) As Long
    'pour ouvrir la fenêtre
    Private Declare Function ShowWindow Lib "user32" (ByVal hWnd As Long, _
                        ByVal nCmdShow As Long) As Long
    'pour vérifier si Lotus est ouvert
    Private Declare Function FindWindow Lib "user32" Alias _
        "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
         
    Dim sSrvr As String 'Le serveur de mail de l'utilisateur courant
    Dim MailDbName As String 'Le nom de la base mail de l'utilisateur courant
    Dim UserName As String 'Le nom de l'utilisateur courant
      
    Dim retVal As Variant 'La valeur de retour de la fonction
      
    '---------------- fonction ouverture de session Notes -----------
    Function CreateNotesSession() As Boolean
        Const notesclass$ = "NOTES"
        Const SW_SHOWMAXIMIZED = 3 'plein ecran
        Const SW_SHOWMMINIZED = 2 'reduire
        Const SW_SHOWWINDOW = 1 'fenetre
        Const SW_SHOW = 5
         
        Dim Lotus_Session As Object
        Dim rc&
        Dim lotusWindow&
         
    '    lotusWindow = FindWindow(notesclass, vbNullString)
      
    '    sSrvr = Lotus_Session.GETENVIRONMENTSTRING("MailServer", True)
    '    MailDbName = Lotus_Session.GETENVIRONMENTSTRING("MailFile", True)
    '    UserName = Lotus_Session.UserName
         
    '    DoEvents
        'Ouverture de Lotus Notes
        'Mettre votre chemin d'accès pour notes.exe et notes.ini'
         'retVal = Shell("C:\Program Files\lotus\notes\notes.exe =C:\Program Files\lotus\notes\notes.ini", vbMaximizedFocus)
     
        'verifier que Lotus est bien ouvert (recupere le handle)
        lotusWindow = FindWindow(notesclass, vbNullString)
        If lotusWindow <> 0 Then
            rc = ShowWindow(lotusWindow, SW_SHOW)
            rc = SetForegroundWindow(lotusWindow)
            CreateNotesSession = True
        Else
             CreateNotesSession = False
        End If
    End Function
    
    
    
    
    
    
    Private Sub CommandButton1_Click()
    
     Const EMBED_ATTACHMENT As Integer = 1454
        Const EMBED_OBJECT As Integer = 1453
        Const EMBED_OBJECTLINK As Integer = 1452
          
        Dim s As Object ' use back end classes to obtain mail database name
        Dim db As Object '
        Dim doc As Object ' front end document
        Dim beDoc As Object ' back end document
        Dim workspace As Object ' use front end classes to display to user
        Dim bodypart As Object '
        Dim bodyAtt As Object '
        Dim lbsession As Boolean
          
        lbsession = CreateNotesSession
          
        If lbsession Then
            'cree la session Lotus Notes
            Set s = CreateObject("Notes.Notessession")
            'se connecte a sa database
            Set db = s.getDatabase(sSrvr, MailDbName)
            If db.IsOpen = True Then
                'database deja ouvert
            Else
                Call db.Openmail
            End If
            'cree un document memo
            Set beDoc = db.CreateDocument
            beDoc.Form = "Memo"
             
             'construction du mail
            Set bodypart = beDoc.CreateRichTextItem("Body")
            'beDoc.From = "Moi" 'inutile
            beDoc.SendTo = UserFormEMail.TextBox9.Value
            beDoc.CopyTo = CCToAdr
            beDoc.BlindCopyTo = BCCToAdr
            beDoc.Subject = UserFormEMail.TextBox10.Value & " Pendiente"
            
           
    With bodypart
    .AppendText "Buenos Dias,"
    .AddNewline 2
    .AppendText "Usted podrìa enviarme el Order Entry Form del (de los) proyecto(s) sigienete(s):"
    .AddNewline 2
    For i = 0 To UserFormEMail.ListBox2.ListCount - 1
    .AppendText UserFormEMail.ListBox2.List(i) & " --- " & UserFormEMail.ListBox3.List(i)
    .AddNewline 2
    Next i
    .AddNewline 2
    .AppendText "Un saludo Cordial"
    .AddNewline 1
    .AppendText "Bruno Antoniol"
    .AddNewline 3
    End With
    
            '-----------------------------------------
            'Remarque s'il y a des destinataires multiples, il suffit de mettre un tableau
            'd'e-mail dans SendTo (CopyTo,BlindCopyTo)
            'exemple :
            'Dim recip(25) as variant
            'recip(0) = "emailaddress1"
            'recip(1) = "emailaddress2" e.t.c
            'beDoc.sendto = recip
            '----------------------------------------
            ' documents joint 1
            If Len(Attach1) > 0 Then
                If Len(dir(Attach1)) > 0 Then
                   Set bodyAtt = bodypart.EmbedObject(EMBED_ATTACHMENT, "", Attach1, dir(Attach1))
                End If
            End If
          
            ' documents joint 2
            If Len(Attach2) > 0 Then
                If Len(dir(Attach2)) > 0 Then
                    Call bodyAtt.EmbedObject(EMBED_ATTACHMENT, "", Attach2, dir(Attach2))
                End If
            End If
                 
            'Affichage du mail dans Lotus Notes
            Set workspace = CreateObject("Notes.NotesUIWorkspace")
            Call workspace.EditDocument(True, beDoc).FieldSetText("Body", "CORPS DE MESSAGE")
                
    
    
          
            Set s = Nothing
            Else
                MsgBox "Votre Lotus Notes est fermé !"
        End If
    
    
    End Sub
    0
  2. senecartour Messages postés 391 Statut Membre 3
     
    Bonjour,

    je me permets de m'adresser à vous même si la discussion date depuis quelques temps. Mais je pense que vous connaissez la solution de mon problème qui est d'envoyer automatiquement le contenu d'excel via la messagerie Lotus Note.

    En effet, je souhaiterais envoyer le contenu d'un fichier excel automatiquement via Lotus note après avoir cliquer sur un bouton.

    voici à quoi ressemble mon fichier https://www.cjoint.com/c/DAqvFzpOIdo

    Je vous remercie beaucoup pour votre partage.

    Coridlament
    0