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
| Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim xRgSel As Range, cel As Range, rng As Range
Dim xOutApp As Object
Dim xMailItem As Object
Dim xMailBody As String
Application.ScreenUpdating = False
Set xRg = Range("AP1:AP200")
Set xRgSel = Intersect(Target, xRg)
If Not xRgSel Is Nothing Then
Me.Unprotect 1234
For Each cel In xRgSel.Cells
If UCase(cel.Value) = "X" Then
Set rng = Intersect(cel.EntireRow, Me.Columns("C:H"))
rng.Value = rng.Value
cel.EntireRow.Cells(1, "B").Value = "X"
End If
Next cel
Me.Protect 1234
End If
Set xRgSel = Range("B4:B273")
Set xRgSel = Intersect(Target, xRgSel)
ActiveWorkbook.Save
If Not xRgSel Is Nothing Then
On Error Resume Next
Application.DisplayAlerts = False
Set xOutApp = CreateObject("Outlook.Application")
Set xMailItem = xOutApp.CreateItem(0)
xMailBody = "Bonjour à tous," & vbNewLine & vbNewLine & _
"Un nouvel " & Cells(Target.Row, 25) & " à été ajouté " & Cells(Target.Row, 8) & " (" & Cells(Target.Row, 9) & ")" & " dans le fichier, en cellule " & xRgSel.Address(False, False) & _
"' le " & _
Format$(Now, "mm/dd/yyyy") & " à " & Format$(Now, "hh:mm") & _
" par " & Environ$("username") & "." & vbNewLine & vbNewLine & _
"Pour rappel le fichier est consultable à cette adresse : " & ThisWorkbook.FullName & vbNewLine & vbNewLine & _
"Merci par avance pour votre validation express," & vbNewLine & vbNewLine & _
""
With xMailItem
.To = Cells(Target.Row, 14) & Cells(Target.Row, 18)
.Cc = ""
.Subject = "Validation de votre part "
.Body = xMailBody
.Display
End With
Set xRgSel = Nothing
Set xOutApp = Nothing
Set xMailItem = Nothing
Application.DisplayAlerts = True
On Error GoTo 0
End If
Application.ScreenUpdating = True
End Sub |
Partager