Bonjour,
J'utilise le code suivant pour envoyer par email le classeur actif contenant la macro.
Comment puis je le modifier pour n'envoyer que la feuille ou l'onglet actif?
Merci beaucoup
J'utilise le code suivant pour envoyer par email le classeur actif contenant la macro.
VB:
Private Sub Mail_workbook_Outlook_2()
'Mail a copy of the ActiveWorkbook with another file name
Dim wb1 As Workbook
Dim TempFilePath As String
Dim TempFileName As String
Dim FileExtStr As String
Dim FileNameStr As String
Dim OutApp As Object
Dim OutMail As Object
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
Set wb1 = ActiveWorkbook
FileNameStr = Range("AT1").Value
'Make a copy of the file/Open it/Mail it/Delete it
'If you want to change the file name then change only TempFileName
TempFilePath = Environ$("temp") & "\"
TempFileName = FileNameStr
FileExtStr = ".xlsm"
wb1.SaveCopyAs TempFilePath & TempFileName & FileExtStr
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.to = Range("ah2") & ";" & Range("ah3") & ";" & Range("ah4")
.CC = Range("AO11")
.BCC = Range("AO5") & ";" & Range("al5")
.Subject = ""
.Body = ""
.Attachments.Add TempFilePath & TempFileName & FileExtStr
'You can add other files also like this
'.Attachments.Add ("C:\test.txt")
.Send 'or use .Display
End With
On Error GoTo 0
'Delete the file
Kill TempFilePath & TempFileName & FileExtStr
Set OutMail = Nothing
Set OutApp = Nothing
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
End Sub
Comment puis je le modifier pour n'envoyer que la feuille ou l'onglet actif?
Merci beaucoup