Envoi mail - joindre fichier excel

Résolu
cs_liouliou Messages postés 2 Date d'inscription lundi 25 février 2008 Statut Membre Dernière intervention 4 mars 2008 - 25 févr. 2008 à 14:56
cs_liouliou Messages postés 2 Date d'inscription lundi 25 février 2008 Statut Membre Dernière intervention 4 mars 2008 - 4 mars 2008 à 14:01
Bonjour à tous,

voila je me lance dans le VB pour le boulot, j'ai réussi jusqu'à présent à me débrouiller sur quelques fonctions simples, mais là ça se complique et je sèche complètement, je n'y arrive plus ...

Je voudrais à partir d'un bouton de commande : envoyer la feuille excel par mail mais aussi attacher d'autres fichiers (j'ai créé un bouton de commande séparemment qui va rechercher les fichiers mais je n'arrive pas à insérer ces fichiers dans le mail). Je pense qu'il faut que je modifie mon code mais je ne sais pas où

Private Sub bouton_click()
    Dim FileExtStr As String
    Dim FileFormatNum As Long
    Dim Sourcewb As Workbook
    Dim Destwb As Workbook
    Dim TempFilePath As String
    Dim TempFileName As String
    
    With Application
        .ScreenUpdating = False
        .EnableEvents = False
    End With
 
    Set Sourcewb = ActiveWorkbook
 
    ActiveSheet.Copy
    Set Destwb = ActiveWorkbook
 
     With Destwb
        If Val(Application.Version) < 12 Then
            'You use Excel 97-2003            FileExtStr ".xls": FileFormatNum -4143
        Else
                     If Sourcewb.Name = .Name Then
                With Application
                    .ScreenUpdating = True
                    .EnableEvents = True
                End With
                MsgBox "Your answer is NO in the security dialog"
                Exit Sub
            Else
                Select Case Sourcewb.FileFormat                Case 51: FileExtStr ".xlsx": FileFormatNum 51
                Case 52:
                    If .HasVBProject Then                        FileExtStr ".xlsm": FileFormatNum 52
                    Else                        FileExtStr ".xlsx": FileFormatNum 51
                    End If                Case 56: FileExtStr ".xls": FileFormatNum 56                Case Else: FileExtStr ".xlsb": FileFormatNum 50
                End Select
            End If
        End If
    End With
 
    '      TempFilePath = Environ$("temp") & ""
    TempFileName = Sourcewb.Name
 
    With Destwb
   
    .SaveAs TempFilePath & TempFileName & FileExtStr, FileFormat:=FileFormatNum
        On Error Resume Next
       
        .SendMail "[mailto:aaa@aaa.com aaa@aaa.com]", _
                  "object" 
               
        On Error GoTo 0
        .Close SaveChanges:=False
    End With
   
 
    'Delete the file you have send
    Kill TempFilePath & TempFileName & FileExtStr
 
    With Application
        .ScreenUpdating = True
        .EnableEvents = True
    End With
End Sub



help me please !!!
j'espère que ces infos suffisent

Merci

3 réponses

PCPT Messages postés 13272 Date d'inscription lundi 13 décembre 2004 Statut Membre Dernière intervention 3 février 2018 47
25 févr. 2008 à 15:21
<li>
Vous êtes ici : [infomsg.aspx Thèmes] / [infomsgf_VB-NET-VB-2005_40.aspx VB.NET et VB 2005] / [infomsgt_DIVERS_221.aspx Divers] / [infomsgt_DEBUTANTS_227.aspx Débutants] / envoi mail - joindre fichier excel</li>


déplacé vers VBA
3
cs_MPi Messages postés 3877 Date d'inscription mardi 19 mars 2002 Statut Membre Dernière intervention 17 août 2018 23
26 févr. 2008 à 00:03
Si tu utilises Outlook (pas Express...) tu pourrais utiliser l'Automation en créant des objets Outlook

Tu pourrais faire une recherche sur Outlook.Application si ça te paraît être une solution. Avec Attachments, tu pourrais insérer les fichiers que tu souhaites.
Voir aussi MailItem

MPi²
Pour ceux qui programment sous Office, n'oubliez pas qu'il existe un forum dédié à ces applications VBA....... ICI
0
cs_liouliou Messages postés 2 Date d'inscription lundi 25 février 2008 Statut Membre Dernière intervention 4 mars 2008
4 mars 2008 à 14:01
Merci pour l'aide,
je vais voir comment je peux faire ...
0
Rejoignez-nous