IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Macros et VBA Excel Discussion :

Affichage de Mail avant envoi. [XL-2007]


Sujet :

Macros et VBA Excel

  1. #1
    Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Novembre 2011
    Messages
    58
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Novembre 2011
    Messages : 58
    Points : 54
    Points
    54
    Par défaut
    Bonjour,

    J'aimerai modifier le code suivant:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    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
     
     
    End Sub
    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.

    Je cherche depuis bien 5h mais je n'y arrive pas!

    Help!

    Bruno

    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

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    '---------- 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
    Bonjour le Forum,

    Petite relance car je suis dans une impasse :-(

    N'importe quelles idées sont les bienvenues! Je suis prêt á tout tester!

    C'est surement une syntaxe que je ne connais pas!

    Merci

  2. #2
    Membre habitué Avatar de Djohn
    Profil pro
    Inscrit en
    Février 2007
    Messages
    309
    Détails du profil
    Informations personnelles :
    Âge : 43
    Localisation : France

    Informations forums :
    Inscription : Février 2007
    Messages : 309
    Points : 140
    Points
    140
    Par défaut
    Salut Bruno,
    Ton code est assez complexe pour mes connaissances, cependant pourquoi ne pas mettre en commentaire la ligne SEND qui se charge d'envoyer le mail ?
    De cette maniere le mail sera sous tes yeux, mais non envoyé.

    C'est ce que je fais sous Outlook.

  3. #3
    Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Novembre 2011
    Messages
    58
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Novembre 2011
    Messages : 58
    Points : 54
    Points
    54
    Par défaut
    Bonjour, Merci de m'aider.

    J'ai déjà essayer mais ça ne marche pas.

    Je reste ouvert à toutes autre idées!

    Je crois que j'ai tout essayé!

    Je viens aussi de m'inscrire sur 3 forums anglais donc je touche du bois!!

    Bruno

  4. #4
    Membre habitué Avatar de Djohn
    Profil pro
    Inscrit en
    Février 2007
    Messages
    309
    Détails du profil
    Informations personnelles :
    Âge : 43
    Localisation : France

    Informations forums :
    Inscription : Février 2007
    Messages : 309
    Points : 140
    Points
    140
    Par défaut
    pour info je te donne le code que j'utilise, si ca peut te servir.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    Sub envoi_mail()
    Dim OutApp As Object
        Dim OutMail As Object
     
        Set OutApp = CreateObject("Outlook.Application")
        OutApp.Session.Logon
        Set OutMail = OutApp.CreateItem(0)
     
        On Error Resume Next
        With OutMail
            .To = "nom@domaine.fr"
            .CC = "quituveux@domaine.com"
            .Subject = "VALUATION SIGN OFF "
            .VotingOptions = "REVIEWED AND BELIEVE THEM TO BE FAIR & REASONABLE;REFUSE"
            .Body = BodyMessage 'variable ou l'ensemble du corps du message est enregistré        
    .Attachments.Add cheminenvoi 
            '.Send 'c'est ici que je bloque l'envoi
            .Display
        End With
        On Error GoTo 0
     
        Set OutMail = Nothing
        Set OutApp = Nothing
    End Sub

  5. #5
    Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Novembre 2011
    Messages
    58
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Novembre 2011
    Messages : 58
    Points : 54
    Points
    54
    Par défaut
    C'est bon voila le code que j'utilise (2 eme code):

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    '---------- 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
     
     For i = 0 To UserFormEMail.ListBox2.ListCount - 1
    Textei = Textei & ListBox2.List(i) & " --- " & ListBox3.List(i) & Chr(10) & Chr(10)
    Next i
     
            'Affichage du mail dans Lotus Notes
           Set workspace = CreateObject("Notes.NotesUIWorkspace")
            Call workspace.EditDocument(True, beDoc).FieldSetText("Body", "Bonjour Monsieur " & TextBox1 & " " & ComboBox1 & "," & Chr(10) & Chr(10) & _
    "Je vous écrit concernant les projets: " & Listei & Chr(10) & Chr(10) & _
    "Afin que vous apportiez les précisions suivantes: " & CheckBox1.Caption & _
    " avant la date suivante: " & TextBox2 & Chr(10) & Chr(10) & Chr(10) & " Meilleures Salutations.Bruno")            
     
     
     
            Set s = Nothing
            Else
                MsgBox "Votre Lotus Notes est fermé !"
        End If
     
     
    End Sub
    Merci, Bruno

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 0
    Dernier message: 16/07/2013, 02h46
  2. [AC-2010] Aperçu du mail avant envoi
    Par docjo dans le forum VBA Access
    Réponses: 0
    Dernier message: 01/05/2013, 13h19
  3. [AC-2000] Préremplir et afficher un mail avant envoi
    Par lbrun79 dans le forum VBA Access
    Réponses: 0
    Dernier message: 07/11/2010, 11h49
  4. [MailMessage]Afficher un mail avant envoi
    Par Mcfly123 dans le forum Général Dotnet
    Réponses: 1
    Dernier message: 17/04/2007, 10h15
  5. [Mail] verifie une adresse mail avant envoi
    Par nebil dans le forum Langage
    Réponses: 3
    Dernier message: 29/03/2006, 01h12

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo