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 :

Envoyer fichier Excel actif via Lotus [XL-2003]


Sujet :

Macros et VBA Excel

  1. #1
    Futur Membre du Club
    Homme Profil pro
    Inscrit en
    Décembre 2012
    Messages
    11
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Décembre 2012
    Messages : 11
    Points : 7
    Points
    7
    Par défaut Envoyer fichier Excel actif via Lotus
    Bonjour,

    J'ai repris un code permettant d'envoyer un fichier excel par mail via lotus, j'aimerais votre aide pour améliorer mon code.

    Voici mon 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
    155
     
    Option Explicit
     
    Const EMBED_ATTACHMENT As Long = 1454
     
     
    Const stPath As String = "c:"
     
     
     
    Sub Send_Active_Sheet()
     
     
      Dim MaDate As String
     
      Dim stFileName As String
     
      Dim vaRecipients As Variant
     
      Dim vaCopyTo 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 String
     
      Dim stSubject As String
     
     
      MaDate = Date
     
      stSubject = "Daily event report PB PARIS" & " " & MaDate
     
      vaMsg = "Bonjour, " & vbCrLf & vbCrLf & vbCrLf & vbCrLf & _
    "Veuillez trouver en pièce jointe le fichier des Pcodes sales PB PARIS du" & " " & MaDate & ":" & _
    vbCrLf & vbCrLf & vbCrLf & vbCrLf & "Regards " & vbCrLf & vbCrLf & vbCrLf & _
    "StSignature"
     
     
      'Copy the active sheet to a new temporarily workbook.
     
      With ActiveSheet
     
        .Copy
     
        stFileName = "Daily event report PB PARIS"
     
      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 = "toto@roro.fr"
     
      'vaCopyTo = ""
     
     
      '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 = ""
     
        .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 "The e-mail has successfully been created and distributed", vbInformation
     
     
    End Sub
    Le mail envoyé grâce à cette macro est dans le PJ ci-dessous.

    Mes questions sont les suivantes:

    1) Peut-on modifier le code de façon a mettre la date du jour (de la variable MaDate) dans le nom du fichier envoyé en PJ ?

    2) Peut-on mettre dans le code une référence à la signature de ma boîte mail de façon à ce que le message envoyé ait ma signature?

    3) Peut-on envoyer le mail non pas à partir de ma boîte mail perso mais en utilisant une boîte mail générique à mon service ? Comment je pourrais réaliser cela ?

    4) Peut-on modifier ce code de façon à ce qu'on me demande de vérifier le mail avant qu'il ne s'envoie ?

    Bien cordialement.
    Images attachées Images attachées  

  2. #2
    Expert éminent
    Avatar de Oliv-
    Homme Profil pro
    solution provider
    Inscrit en
    Mars 2006
    Messages
    4 087
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 53
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : solution provider

    Informations forums :
    Inscription : Mars 2006
    Messages : 4 087
    Points : 7 168
    Points
    7 168
    Billets dans le blog
    20
    Par défaut
    Citation Envoyé par Plc8919 Voir le message

    1) Peut-on modifier le code de façon a mettre la date du jour (de la variable MaDate) dans le nom du fichier envoyé en PJ ?
    oui tu mets date$ dans ton nom de fichier
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
     stFileName = "Daily event report PB PARIS" & date$

    2) Peut-on mettre dans le code une référence à la signature de ma boîte mail de façon à ce que le message envoyé ait ma signature?
    Il vaut mieux mettre la signature dans le code, sinon il faut cocher l'option dans lotus pour que la signature soit automatique
    3) Peut-on envoyer le mail non pas à partir de ma boîte mail perso mais en utilisant une boîte mail générique à mon service ? Comment je pourrais réaliser cela ?
    oui il faut changer la partie
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Set noDatabase = noSession.GETDATABASE("", "")
    pour s'identifeir sur une autre session
    4) Peut-on modifier ce code de façon à ce qu'on me demande de vérifier le mail avant qu'il ne s'envoie ?
    oui tu mets un truc
    à la place de .send
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    If MsgBox("Vérifier ?", vbYesNo) = vbYes Then
                'Affichage du mail dans Lotus Notes
                Dim workspace
                Set workspace = CreateObject("Notes.NotesUIWorkspace")
                Call workspace.EditDocument(True, noDocument).FieldSetText("Body", vaMsg)
     
            Else
                .Send 0, vaRecipients
            End If

  3. #3
    Futur Membre du Club
    Homme Profil pro
    Inscrit en
    Décembre 2012
    Messages
    11
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Décembre 2012
    Messages : 11
    Points : 7
    Points
    7
    Par défaut
    Bonjour,

    Merci pour votre aide c'est vraiment niquel, j'ai juste quelques précisions à vous demander.

    Avec le code suivant (sans les infos privées):

    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
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
     
    Option Explicit
     
    Const EMBED_ATTACHMENT As Long = 1454
     
     
    Const stPath As String = "c:"
     
     
     
    Sub Send_Active_Sheet2()
     
     
      Dim MaDate As String
     
      Dim stFileName As String
     
      Dim vaRecipients As Variant
     
      Dim vaCopyTo 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
     
     
      stSubject = "Daily event report PB PARIS" & "" & Date$
     
      MaDate = Date
     
     
     
      vaMsg = "Bonjour, " & vbCrLf & vbCrLf & vbCrLf & vbCrLf & _
    "Veuillez trouver en pièce jointe le fichier des Pcodes sales PB PARIS du" & "" & MaDate & ":" & _
    vbCrLf & vbCrLf & vbCrLf & vbCrLf & "Regards " & vbCrLf & vbCrLf & vbCrLf & vbCrLf & vbCrLf & vbCrLf & _
    "toto" & vbCrLf & _
    "+" & "xx" & "(" & "x" & ")" & "xxxxx" & vbCrLf & vbCrLf & _
    "fqsfqgqfqf" & vbCrLf & _
    "gegzsegzeg" & "" & "|" & "" & "xxxx" & vbCrLf & _
    "xxx" & "," & "" & "xxxxxxx" & vbCrLf & _
    "75008 Paris" & "" & "-" & "" & "France"
     
     
      'Copy the active sheet to a new temporarily workbook.
     
      With ActiveSheet
     
        .Copy
     
        stFileName = "Daily event report PB PARIS" & Date$
     
      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 = "toto@roro.fr"
     
      'vaCopyTo = ""
     
     
      '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 = ""
     
        .Subject = stSubject
     
        .Body = vaMsg
     
        .SaveMessageOnSend = True
     
        .PostedDate = Now()
     
        '.Send 0, vaRecipients
     
            If MsgBox("Vérifier ?", vbYesNo) = vbYes Then
                'Affichage du mail dans Lotus Notes
                Dim workspace
                Set workspace = CreateObject("Notes.NotesUIWorkspace")
                Call workspace.EditDocument(True, noDocument).FieldSetText("Body", vaMsg)
                MsgBox "please look your lotus windows for checking", vbInformation
                Else
                    .Send 0, vaRecipients
                    MsgBox "The e-mail has successfully been created and distributed", vbInformation
            End If
      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
     
     
     
    End Sub
    J'obtiens un mail dont le format de Date$ est en format us avec le mois avant le jour, comment pourrais-je modifier ce format de date ?

    La deuxième chose c'est que parfois la signature automatique de lotus apparaît dans le mail que j'envoie et elle apparaît en plein milieu du mail, y aurait-il un moyen de désactiver la signature automatique de lotus le temps du lancement de la macro et puis de la réactiver par la suite ?


    Très chaleureusement.
    Pierre.

  4. #4
    Expert éminent
    Avatar de Oliv-
    Homme Profil pro
    solution provider
    Inscrit en
    Mars 2006
    Messages
    4 087
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 53
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : solution provider

    Informations forums :
    Inscription : Mars 2006
    Messages : 4 087
    Points : 7 168
    Points
    7 168
    Billets dans le blog
    20
    Par défaut
    Salut,
    Pour la date :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    MsgBox DatePart("d", Date) & "-" & DatePart("m", Date) & "-" & DatePart("yyyy", Date)

    Pour la signature ca doit ce passer par là
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
     Call workspace.EditDocument(True, noDocument).FieldSetText("Body", vaMsg)
    je sais que si tu mets juste.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
     Call workspace.EditDocument(True, noDocument)
    ton message est écrit après la signature.

    Au fait es tu obligé de passer par Lotus sinon utilises CDO !

    Salut,
    Pour le format de la date on peut aussi utiliser
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Format$(Date, "dd-mm-yyyy")

  5. #5
    Futur Membre du Club
    Homme Profil pro
    Inscrit en
    Décembre 2012
    Messages
    11
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Décembre 2012
    Messages : 11
    Points : 7
    Points
    7
    Par défaut
    Hello, merci pour tout !! Tout marche à la perfection! Je laisse le message suivant pour donner l'info à ceux qui veulent

    Citation Envoyé par Oliv- Voir le message
    Salut,
    Pour la date :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Format$(Date, "dd-mm-yyyy")
    .
    J'ai modifié le format de ma variable:
    MaDate = Format$(Date$, "dd-mm-yyyy")

    Citation Envoyé par Oliv- Voir le message
    Pour la signature ca doit ce passer par là
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
     Call workspace.EditDocument(True, noDocument).FieldSetText("Body", vaMsg)
    je sais que si tu mets juste.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
     Call workspace.EditDocument(True, noDocument)
    ton message est écrit après la signature.
    J'ai bien cherché pour trouver et j'ai finalement trouvé sur un site américain. Voici la solution:
    A la place de :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Call workspace.EditDocument(True, noDocument).FieldSetText("Body", vaMsg)
    mettre:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     Set notesUIDoc = workspace.EditDocument(True, noDocument)
                Call notesUIDoc.GOTOFIELD("Body")
                Call notesUIDoc.FieldClear("Body")
                Call notesUIDoc.FieldAppendText("Body", vaMsg)
    Ca nettoie le mail pour enlever signature automatique, puis ça réinjecte le message.

    Je mets en statut Résolu!

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

Discussions similaires

  1. Fichier excel actif mais non ouvert
    Par Silvanos dans le forum Macros et VBA Excel
    Réponses: 5
    Dernier message: 28/02/2013, 17h56
  2. [Sources] Comment envoyer un e-mail via Lotus Notes ?
    Par Heydrickx dans le forum Contribuez
    Réponses: 0
    Dernier message: 16/12/2012, 12h03
  3. Réponses: 3
    Dernier message: 14/03/2011, 14h25
  4. Créer macro dans un fichier excel crée via VB.NET
    Par Florian54 dans le forum VB.NET
    Réponses: 2
    Dernier message: 13/01/2011, 09h22
  5. [XL-2007] Transfert du fichier Excel Actif par FTP depuis une macro
    Par DavyBernhard dans le forum Macros et VBA Excel
    Réponses: 1
    Dernier message: 26/07/2009, 21h55

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