Note: The other languages of the website are Google-translated. Back to English
Inloggen  \/ 
x
or
x
Registreer  \/ 
x

or

Hoe verzend ik een e-mail als een bepaalde cel is gewijzigd in Excel?

Dit artikel gaat over het verzenden van e-mail via Outlook als een cel in een bepaald bereik in Excel wordt gewijzigd.

Stuur een e-mail als een cel in een bepaald bereik is gewijzigd met VBA-code


Stuur een e-mail als een cel in een bepaald bereik is gewijzigd met VBA-code


Als u automatisch een nieuwe e-mail moet maken met een actieve werkmap als bijlage wanneer cellen in het bereik A2: E11 worden gewijzigd in een bepaald werkblad, kan de volgende VBA-code u helpen.

1. In het werkblad dat u e-mail moet verzenden op basis van de gewijzigde cel in een bepaald bereik, klikt u met de rechtermuisknop op de bladtab en klikt u vervolgens op de Bekijk code vanuit het contextmenu. Zie screenshot:

2. In het opduiken Microsoft Visual Basic voor toepassingen venster, kopieer en plak de onderstaande VBA-code in het codevenster.

VBA-code: stuur een e-mail als een cel in een opgegeven bereik is gewijzigd in Excel

Private Sub Worksheet_Change(ByVal Target As Range)
'Updated by Extendoffice 2017/9/12
    Dim xRgSel As Range
    Dim xOutApp As Object
    Dim xMailItem As Object
    Dim xMailBody As String
    On Error Resume Next
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    Set xRg = Range("A2:E11")
    Set xRgSel = Intersect(Target, xRg)
    ActiveWorkbook.Save
    If Not xRgSel Is Nothing Then
        Set xOutApp = CreateObject("Outlook.Application")
        Set xMailItem = xOutApp.CreateItem(0)
        xMailBody = "Cell(s) " & xRgSel.Address(False, False) & _
            " in the worksheet '" & Me.Name & "' were modified on " & _
            Format$(Now, "mm/dd/yyyy") & " at " & Format$(Now, "hh:mm:ss") & _
            " by " & Environ$("username") & "."

        With xMailItem
            .To = "Email Address"
            .Subject = "Worksheet modified in " & ThisWorkbook.FullName
            .Body = xMailBody
            .Attachments.Add (ThisWorkbook.FullName)
            .Display
        End With
        Set xRgSel = Nothing
        Set xOutApp = Nothing
        Set xMailItem = Nothing
    End If
    Application.DisplayAlerts = True
    Application.ScreenUpdating = True
End Sub

Notes:

1). In de code, A2: E11 is het bereik waarop u e-mail verzendt op basis van.
2). Wijzig de hoofdtekst van de e-mail in xMailBody regel in de code.
3). Vervang de Email adres met het e-mailadres van de ontvanger in de rij .To = "E-mailadres".
4). Wijzig het onderwerp van de e-mail in de rij .Subject = "Werkblad gewijzigd in" & ThisWorkbook.FullName.

3. druk de anders + Q toetsen tegelijk om het Microsoft Visual Basic voor toepassingen venster.

Vanaf nu wordt elke cel in het bereik A2: E11 gewijzigd, er wordt een nieuwe e-mail gemaakt met de bijgewerkte werkmap als bijlage. En alle gespecificeerde velden zoals onderwerp, ontvanger en e-mailtekst worden in de e-mail vermeld. Stuur de e-mail.

Opmerking:: De VBA-code werkt alleen als u Outlook als uw e-mailprogramma gebruikt.


Gerelateerde artikelen:


De beste tools voor kantoorproductiviteit

Kutools voor Excel lost de meeste van uw problemen op en verhoogt uw productiviteit met 80%

  • visfuik: Snel invoegen complexe formules, grafieken en alles wat je eerder hebt gebruikt; Versleutel cellen met wachtwoord; Maak een mailinglijst en stuur e-mails ...
  • Super Formula-balk (bewerk eenvoudig meerdere regels tekst en formule); Lay-out lezen (gemakkelijk grote aantallen cellen lezen en bewerken); Plakken in gefilterd bereik...
  • Voeg cellen / rijen / kolommen samen zonder gegevens te verliezen; Gespleten cellen inhoud; Combineer dubbele rijen / kolommen... Voorkom dubbele cellen; Vergelijk Ranges...
  • Selecteer Dupliceren of Uniek Rijen; Selecteer lege rijen (alle cellen zijn leeg); Super zoeken en fuzzy zoeken in veel werkboeken; Willekeurige selectie ...
  • Exacte kopie Meerdere cellen zonder de formuleverwijzing te wijzigen; Maak automatisch verwijzingen naar meerdere bladen; Plaats kogels, Selectievakjes en meer ...
  • Extraheer tekst, Tekst toevoegen, Verwijderen op positie, Ruimte verwijderen; Paging-subtotalen maken en afdrukken; Converteren tussen celinhoud en opmerkingen...
  • Super filter (bewaar en pas filterschema's toe op andere bladen); Geavanceerd sorteren per maand / week / dag, frequentie en meer; Speciaal filter door vet, cursief ...
  • Combineer werkmappen en werkbladen; Tabellen samenvoegen op basis van sleutelkolommen; Gegevens splitsen in meerdere bladen; Batch Converteer xls, xlsx en PDF...
  • Meer dan 300 krachtige functies. Ondersteunt Office / Excel 2007-2019 en 365. Ondersteunt alle talen. Eenvoudig te implementeren in uw onderneming of organisatie. Gratis proefperiode van 30 dagen met volledige functies. 60 dagen geld-terug-garantie.
kte tabblad 201905

Office-tabblad Brengt een interface met tabbladen naar Office en maakt uw werk veel gemakkelijker

  • Schakel bewerken en lezen met tabbladen in Word, Excel, PowerPoint in, Publisher, Access, Visio en Project.
  • Open en maak meerdere documenten in nieuwe tabbladen van hetzelfde venster in plaats van in nieuwe vensters.
  • Verhoogt uw productiviteit met 50% en vermindert elke dag honderden muisklikken voor u!
officetab onderkant
Say something here...
symbols left.
You are guest
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    HumAnCK · 7 months ago
    Hello, i was trying to send emails on my sheet using one value changed on the sheet. If on column H the status will be changed to ="4" the Order ID in the left should be send to one user. The sheet works dynamicly so i have a Range from D9:D140 where order id's are stored and status changes are made in the same range on H9:H140. How can i reach the goal to do so and send the Order ID to my customer when status has been changed to ="4" ?
  • To post as a guest, your comment is unpublished.
    james2706 · 2 years ago
    Hello. How do I modify the code so that an e-mail is sent to another e-mail address if another range of cells is edited?
    • To post as a guest, your comment is unpublished.
      joseph · 2 years ago
      Any help on this request? I am having same issue. I want to add multiple email address per row, but when I change one row, the entire worksheet changes. How can I limit the changes only to one row?
      • To post as a guest, your comment is unpublished.
        Pawel · 1 years ago
        Edit linie:
        1). In the code, A2:E11 is the range you will send email based on.
        and
        3). Replace the Email Address with the recipient email address in line .To = "Email Address".

        Works fine.
        • To post as a guest, your comment is unpublished.
          Owen · 1 years ago
          Can you please explain this further. How do you repeat the code to send to a different email based on another range being modified. I have tried copy and pasting the code below and changing as per your comment, but still only the first range seems to execute the command and write the email.
  • To post as a guest, your comment is unpublished.
    Ioana · 2 years ago
    hi; is there a way to change text displayed using information from other cells (from first row and first column)? for example, if I change cell K15, I want to include in the message info on cells A15 and K1? what should I change in the code? thank you very much
    • To post as a guest, your comment is unpublished.
      laya · 6 months ago
      hi Laona. do u find out how can do this?

  • To post as a guest, your comment is unpublished.
    jimmy@globeways.com · 2 years ago
    I have tried above VBA code: Send email if cell in a specified range is modified in Excel. This VBA works for me except sending email. When the data is modified in the given range an email is automatically generated with modified cell details. However, the email is not automatically sending to the recipient and the user has to click send button in the email. What I am looking here is, the email has to send to the recipients automatically when it is generated. Please help me to provide a code for this. Many thanks
    • To post as a guest, your comment is unpublished.
      crystal · 2 years ago
      Hi Jimmy Joseph,
      Please replace the line ".Display" with ".Send". Hope I can help. Thanks for commenting.
  • To post as a guest, your comment is unpublished.
    sagar · 2 years ago
    if i have to send that entire row then?
  • To post as a guest, your comment is unpublished.
    Brad · 2 years ago
    Great information.
    Question regarding the information that can be added to the email.
    Using your example above....

    If you had a value in F4, how would you include the F4 Value in the email that was generated when D4 was modified??
  • To post as a guest, your comment is unpublished.
    Sonu · 2 years ago
    If i want to send the cell value instead of the address..then what shall I change in the code?
    • To post as a guest, your comment is unpublished.
      crystal · 2 years ago
      Hi,
      You can try the below VBA code.

      Private Sub Worksheet_Change(ByVal Target As Range)
      Dim xRgSel As Range
      Dim xOutApp As Object
      Dim xMailItem As Object
      Dim xMailBody As String
      On Error Resume Next
      Application.ScreenUpdating = False
      Application.DisplayAlerts = False
      Set xRg = Range("A2:E11")
      Set xRgSel = Intersect(Target, xRg)
      ActiveWorkbook.Save
      If Not xRgSel Is Nothing Then
      Set xOutApp = CreateObject("Outlook.Application")
      Set xMailItem = xOutApp.CreateItem(0)
      xMailBody = "Cell(s) " & xRgSel.Address(False, False) & _
      xRgSel.Value & _
      " in the worksheet '" & Me.Name & "' were modified on " & _
      Format$(Now, "mm/dd/yyyy") & " at " & Format$(Now, "hh:mm:ss") & _
      " by " & Environ$("username") & "."

      With xMailItem
      .To = "Email Address"
      .Subject = "Worksheet modified in " & ThisWorkbook.FullName
      .Body = xMailBody
      .Attachments.Add (ThisWorkbook.FullName)
      .Display
      End With
      Set xRgSel = Nothing
      Set xOutApp = Nothing
      Set xMailItem = Nothing
      End If
      Application.DisplayAlerts = True
      Application.ScreenUpdating = True
      End Sub
      • To post as a guest, your comment is unpublished.
        Gurpreet singh · 7 months ago
        What if we only want the updated comments in that cell an not the entire cell value
        It should show only the latest comments added in the cell

  • To post as a guest, your comment is unpublished.
    Mahadev · 2 years ago
    Dear Admin,


    I need your help,



    I have an excel to monitor daily work done details by our worker from the field, so is this possible to trigger a mail from excel sheet if that guy failed to update the data in that excel sheet on given time.
    • To post as a guest, your comment is unpublished.
      crystal · 2 years ago
      Hi,
      Can't help with this.
  • To post as a guest, your comment is unpublished.
    sjones · 2 years ago
    I was able to create the macro, however I'm having a problem. I would like to automatically send an email when a cell reaches a certain threshold. The cell is a formula. When the calculation sum goes below the said threshold it doesn't do anything; however, if I type directly into the cell it will process the macro as planned. Does the formula mess up the macro?
    • To post as a guest, your comment is unpublished.
      crystal · 2 years ago
      Hi Sissy Jones,
      The method in this article: How to automatically send email based on cell value in Excel?
      https://www.extendoffice.com/documents/excel/4656-excel-send-email-based-on-cell-value.html may help you solve the problem.
  • To post as a guest, your comment is unpublished.
    pakxrohn@gmail.com · 3 years ago
    I am stuck in below VB code. I am trying to get email notification to the user where the data has been changed. Email is working but when I make any change email initiated at once but I want email when excel sheet is saved and closed after making all the changes to all users who impacted. Also this should be working for any of the sheets in entire excel workbook.

    Please help...

    Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)

    '****Declaration of objects and variables******

    Dim xRgSel As Range Dim xOutApp As Object Dim xMailItem As Object Dim xMailBody As String Dim mailTo As String

    On Error Resume Next

    Sheets("TargetSheet").Range("TargetRange").Select

    Application.ScreenUpdating = False Application.DisplayAlerts = False

    'Set xRg = Range("A" & Rows.Count).End(xlUp).Row

    Set xRg = Range("A2:DA1000")
    Set xRgSel = Intersect(Target, xRg)


    ActiveWorkbook.Save
    '**********Outlook Application Opening***********

    If Not xRgSel Is Nothing Then

    Set xOutApp = CreateObject("Outlook.Application")
    Set xMailItem = xOutApp.CreateItem(0)

    xMailBody = "Cell(s) " & xRgSel.Address(False, False) & _
    " in the worksheet '" & Me.Name & "' were modified on " & _
    Format$(Now, "mm/dd/yyyy") & " at " & Format$(Now, "hh:mm:ss") & _
    " by " & Environ$("username") & "."
    '***********Finding recipient List************

    If Cells(xRgSel.Row, "A").Value = "Pankaj" Then

    mailTo = "pank12***@gmail.com"

    End If

    If Cells(xRgSel.Row, "A").Value = "Nitin" Then

    mailTo = "pank****@gmail.com"

    End If

    If Cells(xRgSel.Row, "A").Value = "Chandan" Then

    mailTo = "pakxro**@gmail.com"

    End If
    '*************Email composing*************

    With xMailItem

    .To = mailTo
    .Subject = "Worksheet modified in " & ThisWorkbook.FullName
    .Body = xMailBody
    '.Attachments.Add (ThisWorkbook.FullName)
    .Display

    End With

    Set xRgSel = Nothing
    Set xOutApp = Nothing
    Set xMailItem = Nothing

    End If

    Application.DisplayAlerts = True
    Application.ScreenUpdating = True
    End Sub
    • To post as a guest, your comment is unpublished.
      crystal · 3 years ago
      Dear Pankaj Shukla,
      Post your Excel question to our forum: https://www.extendoffice.com/forum.html to get more supports about Excel from our Excel professional.