Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
'========================================================
' GEBRUIKER SELECTEREN - CEL SELECTEERT AUTOMATISCH
'========================================================
' als cel B30 erbij betrokken is mag er niets gebeuren (Outlook mag niet openen)
If Target.Address = "$B$30" Then
If Not Intersect(Target, Range("B30")) Is Nothing Then
' Keuze 1 selecteren => naar cel B2 gaan
If Target.Text = "Keuze 1" Then
Blad1.Select
Blad1.Range("B2").Select
End If
' Keuze 2 selecteren => naar cel C2 gaan
If Target.Text = "Keuze 2" Then
Blad1.Select
Blad1.Range("C2").Select
End If
End If
Exit Sub
'========================================================
' ALS EEN AANPASSING GEBEURT IN EEN ANDERE CEL DAN B30
'========================================================
Else
'========================================================
' INDIEN AANPASSING : MAILEN VIA OUTLOOK
'========================================================
'declareren variabelen
Dim objOL As Object
Dim objMail As Object
Dim OldValue As String
Dim oOutlook As Variant
Dim ol As Outlook.Application
Dim olNameSpace As Outlook.Namespace
Dim olInbox As Outlook.MAPIFolder
Set ol = New Outlook.Application
Set olNameSpace = ol.GetNamespace("MAPI")
Set olInbox = olNameSpace.GetDefaultFolder(olFolderInbox)
'Outlook zichtbaar maken
olInbox.Display
On Error Resume Next
Set objOL = GetObject(, "Outlook.Application")
If Err.Number <> 0 Then
Err.Clear
Set objOL = CreateObject("Outlook.Application")
End If
End If
'Indien geen foutmelding - maak mail
On Error GoTo 0
Set objMail = ol.CreateItem(0)
With objMail
.To = "mail@mail.be"
.Subject = ThisWorkbook.Name & ": Status " & Range(Target.Address).End(xlToLeft).Text & " gewijzigd door " & Range(Target.Address).End(xlUp).Text & " " & Range(Target.Address).End(xlUp).Offset(1, 0).Text
.Body = "In het bestand " & ThisWorkbook.Name & " is de status van '" & Range(Target.Address).End(xlToLeft).Text & "' door " & Range(Target.Address).End(xlUp).Text & " " & Range(Target.Address).End(xlUp).Offset(1, 0).Text & " gewijzigd naar '" & Range(Target.Address) & "' op " & Format(Now, "dd/mm/yyyy") & " om " & Format(Now, "hh:mm:ss") & vbCrLf & "Inhoud cel: " & ActiveCell.Value & " en: " & Target.Cells(1).Value & OldValue & vbCrLf
.Send
End With
Set objOL = Nothing
Set objMail = Nothing
End Sub