Re : petite aide VBA
J'ai résolu mon problème. Voici le code pour ceux que ça peut aider
Sub EnvoiFeuille()
' Works in Excel 2000, Excel 2002, Excel 2003, Excel 2007, Excel 2010, Outlook 2000, Outlook 2002, Outlook 2003, Outlook 2007, Outlook 2010.
Dim Source As Range
Dim Dest As Workbook
Dim wb As Workbook
Dim TempFilePath As String
Dim TempFileName As String
Dim FileExtStr As String
Dim FileFormatNum As Long
Dim OutApp As Object
Dim OutMail As Object
Set Source = Nothing
On Error Resume Next
Set Source = Range("A:N").SpecialCells(xlCellTypeVisible)
On Error GoTo 0
If Source Is Nothing Then
MsgBox "Une des colonnes est manquante ou la feuille est protégée. " & _
"Déverouillez la feuille ou vérifiez les lignes ou colonnes et ré-essayez.", vbOKOnly
Exit Sub
End If
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
Set wb = ActiveWorkbook
Set Dest = Workbooks.Add(xlWBATWorksheet)
Source.Copy
With Dest.Sheets(1)
.Cells(1).PasteSpecial Paste:=8
.Cells(1).PasteSpecial Paste:=xlPasteValues
.Cells(1).PasteSpecial Paste:=xlPasteFormats
.Cells(1).Select
Application.CutCopyMode = False
End With
TempFilePath = Environ$("temp") & "\"
TempFileName = "Selection of " & wb.Name & " " _
& Format(Now, "dd-mmm-yy h-mm-ss")
If Val(Application.Version) < 12 Then
' En cas d'utilisation d'Excel 2000 ou 2003.
FileExtStr = ".xls": FileFormatNum = -4143
Else
' En cas d'utilisation d'Excel 2007 ou 2010.
FileExtStr = ".xlsx": FileFormatNum = 51
End If
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
With Dest
.SaveAs TempFilePath & TempFileName & FileExtStr, _
FileFormat:=FileFormatNum
On Error Resume Next
' POUR CHANGER LES DESTINATAIRES Il faut rentrer l'adresse e-mail dans la ligne ci dessous après To=.
' par exemple To = "xxx1@gmail.com" & "xxx2@gmail.com" & "xxx3@gmail.com etc... l'email sera alors envoyé à xxx1, xxx2 et xxx3.
' Les champs subject et Body peuvent être changés aussi, ils contiennet le corps du message et l'objet 'sujet).
With OutMail
.To = "xxxx@gmail.com"
.Cc = ""
.Bcc = ""
.Subject = "Suivi des actions MDC"
.Body = "Bonjour, vous trouverez dans ce mail la liste des actions à réaliser suite aux forums MDC (récent + relance des anciens). Une fois ces actions effectuées merci d'en informer :" & _
"Sylvie xxx, Caroline xxx, Thibault xxx." & _
"Pour information un formulaire électronique est disponible sur le réseau à cet emplacement : xxxx " & _
" Ce formulaire est à utiliser en priorité par rapport à la version papier." & _
"Cordialement," & _
"AQ Systèmes"
.Attachments.Add Dest.FullName
.Send
End With
On Error GoTo 0
.Close SaveChanges:=False
End With
Kill TempFilePath & TempFileName & FileExtStr
Set OutMail = Nothing
Set OutApp = Nothing
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
End Sub