Re : send email :feuilles uniquement visibles
Hello,
Je veux qu'il fasse qu'une copie, 1 seule fois.. Dans le cas de juju il me copie les feuilles visibles chacune dans un nouveau classeur...
Je souhaiterais qu'il me copie mes feuilles visibles dans un seul nouveau classeur que j'envoie par email.Je veux recevoir un seul fichier excel.
Codé en dur ça fonctionne...mais vu que je ne sais quelles feuilles seront visibles!!là ça bloque!!! Dans mon cas ici, j'ai mis les feuilles result et customerpool pour essayer...
Voici mon programme :
Sub Mail_Sheets_Array()
' Works in Excel 97 through Excel 2007.
Dim FileExtStr As String
Dim FileFormatNum As Long
Dim Sourcewb As Workbook
Dim Destwb As Workbook
Dim TempFilePath As String
Dim TempFileName As String
Dim sh As Worksheet
Dim Mesfeuilles As Object
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
Set Sourcewb = ActiveWorkbook
' Copy the worksheets to a new workbook.
Sourcewb.Sheets(Array("Result", "CustomerPool")).Copy
Set Destwb = ActiveWorkbook
' Determine the Excel version, file extension, and format.
With Destwb
If Val(Application.Version) < 12 Then
' You are using Excel 97 through Excel 2003.
FileExtStr = ".xls": FileFormatNum = -4143
Else
' You are using Excel 2007.
' When you use ActiveSheet.Copy to create a new workbook,
' you are prompted with a security dialog. If you click No
' in the dialog, then the name of Sourcewb is the same
' as Destwb and you exit the subroutine. You only see this
' dialog when you attempt to copy a worksheet from an .xlsm
' file with macros disabled.
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
' Save the new workbook and then mail it.
TempFilePath = Environ$("temp") & "\"
'"Part of " & Sourcewb.Name & " " & Format(Now, "dd-mmm-yy h-mm-ss")
'Sourcewb.Sheets("YourSheet").Range("A1").Value & " " & Format(Now, "dd-mmm-yy h-mm-ss")
TempFileName = "Etude " & Sourcewb.Sheets("Result").Customer.Value & " " & Format(Now, "dd-mmm-yy")
With Destwb
.SaveAs TempFilePath & TempFileName & FileExtStr, FileFormat:=FileFormatNum
On Error Resume Next
.SendMail MailAdresse, _
MailSubject
On Error GoTo 0
.Close SaveChanges:=False
End With
' Delete the file you just sent.
Kill TempFilePath & TempFileName & FileExtStr
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
End Sub