Przejdź do głównej zawartości

Jak wysłać e-mail z przypomnieniem lub powiadomieniem, jeśli skoroszyt jest aktualizowany w programie Excel?

W niektórych przypadkach może być konieczne wyzwolenie powiadomienia e-mail do określonego odbiorcy, jeśli w wysłanym skoroszycie są zaktualizowane dane. Ten artykuł pokaże Ci, jak to osiągnąć.

Wyślij przypomnienie e-mailem lub powiadomienie, jeśli skoroszyt zostanie zaktualizowany kodem VBA


Wyślij przypomnienie e-mailem lub powiadomienie, jeśli skoroszyt zostanie zaktualizowany kodem VBA

Wykonaj następujące czynności, aby wysłać e-mail z przypomnieniem lub powiadomieniem, jeśli skoroszyt zostanie zaktualizowany.

1. W skoroszycie otwórz określony arkusz, w którym wyślesz powiadomienie e-mail na podstawie zaktualizowanych danych w środku.

2. Kliknij prawym przyciskiem myszy kartę arkusza i wybierz Wyświetl kod z menu po kliknięciu prawym przyciskiem myszy. Zobacz zrzut ekranu:

2. w Microsoft Visual Basic for Applications window, skopiuj i wklej następujący kod do okna kodu. Zobacz zrzut ekranu:

Kod VBA: wyślij e-mail z przypomnieniem lub powiadomieniem, jeśli skoroszyt jest aktualizowany

Private Sub Worksheet_Change(ByVal Target As Range)
'Updated by Extendoffice 2017/9/14
    Dim xOutApp As Object
    Dim xMailItem As Object
    Dim xName As String
    Dim xYesOrNo As Integer
    On Error Resume Next
    Set xOutApp = CreateObject("Outlook.Application")
    Set xMailItem = xOutApp.CreateItem(0)
    xYesOrNo = MsgBox("Want to attach updated workbook in email?", vbInformation + vbYesNo, "KuTools For Excel")
    If xYesOrNo = 6 Then ActiveWorkbook.Save
    If xYesOrNo = 6 Then xName = ActiveWorkbook.FullName
    With xMailItem
        .To = "Email Address"
        .cc = ""
        .Subject = "email notification test"
        .Body = "Hi," & Chr(13) & Chr(13) & "File is now updated."
        If xYesOrNo = 6 Then .Attachments.Add xName
        .Display
    End With
    xMailItem = Nothing
    xOutApp = Nothing
End Sub

Note: Zastąp adres e-mail w wierszu adresem e-mail odbiorcy .To = "Adres e-mail". I zmień Cc, Subject, a także pola treści w kodzie VBA, jak potrzebujesz.

3. wciśnij inny + Q klucze do zamknięcia Microsoft Visual Basic for Applications okno.

4. Po edycji komórki w arkuszu, a Kutools dla programu Excel pojawi się okno dialogowe, jak pokazano poniżej. Jeśli chcesz załączyć zaktualizowany skoroszyt do wiadomości e-mail, kliknij plik Tak przycisk. Jeśli nie, kliknij Nie przycisk.

5. Następnie wiadomość e-mail jest tworzona automatycznie z załączonym zaktualizowanym skoroszytem lub bez niego. Wszystkie określone pola są również wymienione w wiadomości e-mail. Proszę kliknąć Wyślij przycisk, aby go wysłać.

Note: Kod VBA działa tylko wtedy, gdy używasz Outlooka jako programu pocztowego.


Podobne artykuły:

Najlepsze narzędzia biurowe

🤖 Pomocnik AI Kutools: Zrewolucjonizuj analizę danych w oparciu o: Inteligentne wykonanie   |  Wygeneruj kod  |  Twórz niestandardowe formuły  |  Analizuj dane i generuj wykresy  |  Wywołaj funkcje Kutools...
Popularne funkcje: Znajdź, wyróżnij lub zidentyfikuj duplikaty   |  Usuń puste wiersze   |  Łącz kolumny lub komórki bez utraty danych   |   Okrągły bez wzoru ...
Super wyszukiwanie: Wiele kryteriów VLookup    Wiele wartości VLookup  |   Przeglądanie pionowe na wielu arkuszach   |   Wyszukiwanie rozmyte ....
Zaawansowana lista rozwijana: Szybko twórz listę rozwijaną   |  Zależna lista rozwijana   |  Lista rozwijana wielokrotnego wyboru ....
Menedżer kolumn: Dodaj określoną liczbę kolumn  |  Przesuń kolumny  |  Przełącz stan widoczności ukrytych kolumn  |  Porównaj zakresy i kolumny ...
Polecane funkcje: Fokus siatki   |  Widok projektu   |   Duży pasek formuły    Menedżer skoroszytów i arkuszy   |  Biblioteka zasobów (Automatyczny tekst)   |  Selektor dat   |  Połącz arkusze   |  Szyfruj/odszyfruj komórki    Wysyłaj e-maile według listy   |  Super filtr   |   Specjalny filtr (filtruj pogrubienie/kursywa/przekreślenie...) ...
15 najlepszych zestawów narzędzi12 Tekst Tools (Dodaj tekst, Usuń znaki, ...)   |   50 + Wykres rodzaje (Wykres Gantta, ...)   |   40+ Praktyczne Wzory (Oblicz wiek na podstawie urodzin, ...)   |   19 Wprowadzenie Tools (Wstaw kod QR, Wstaw obraz ze ścieżki, ...)   |   12 Konwersja Tools (Liczby na słowa, Przeliczanie walut, ...)   |   7 Połącz i podziel Tools (Zaawansowane wiersze łączenia, Podział komórki, ...)   |   ... i więcej

Zwiększ swoje umiejętności Excela dzięki Kutools for Excel i doświadcz wydajności jak nigdy dotąd. Kutools dla programu Excel oferuje ponad 300 zaawansowanych funkcji zwiększających produktywność i oszczędzających czas.  Kliknij tutaj, aby uzyskać funkcję, której najbardziej potrzebujesz...

Opis


Karta Office wprowadza interfejs z zakładkami do pakietu Office i znacznie ułatwia pracę

  • Włącz edycję i czytanie na kartach w programach Word, Excel, PowerPoint, Publisher, Access, Visio i Project.
  • Otwieraj i twórz wiele dokumentów w nowych kartach tego samego okna, a nie w nowych oknach.
  • Zwiększa produktywność o 50% i redukuje setki kliknięć myszką każdego dnia!
Comments (20)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
I am following certificates log in excel sheet. i need to get reminder before the certificates getting expired. please advice me.
This comment was minimized by the moderator on the site
Hi rahul rajan,

Do you want to pop up a reminder based on the date of a cell?
This comment was minimized by the moderator on the site
Hi which part of the code should i delete so it only sends email when i click save and not on every action ?
This comment was minimized by the moderator on the site
Hi donkeh,
In the VBA code, please replace the following line:
.Display
with
.Send
This comment was minimized by the moderator on the site
HOLA CRISTAL, ME GUSTARIA PONERME EN CONTACTO DIRECTO CONTIGO, PARA PEDIR TU AYUDA EN UN PROBLEMITA EN UNA HOJA DE EXCEL
This comment was minimized by the moderator on the site
Hi GERARDO MARTIN OLVERA,
You can email me at .
This comment was minimized by the moderator on the site
HOLA CRISTAL, ME GUSTARIA PONERME EN CONTACTO DIRECTO CONTIGO, NE CESITO DE TU AYUDA EN EXCEL,GRACIAS
This comment was minimized by the moderator on the site
please i am a bit confused but where in the code does it detect the sheet being modified/updated?
i am trying to write a code where the table on a particular sheet gets sent when the table is modified (or more specifically when rows are added)
thank you!
This comment was minimized by the moderator on the site
Hi,
The code in the post detects all cells in the entire worksheet based on the first line of "Private Sub Worksheet_Change(ByVal Target As Range)".
If you want to send an email with a particular table when it is modified, you can try the following VBA.
Note: please change "Table1" to your own table name.
Private Sub Worksheet_Change(ByVal Target As Range)
'Updated by Extendoffice 2022/5/27
    Dim xYesOrNo As Integer
    Dim xTableName As String
    Dim xTableRg As Range
    Dim I, J As Long
    Dim xEmailBody As String
    Dim xMailOut As Object
    Dim xOutApp As Object
    On Error Resume Next
    
    xTableName = "Table1" 'The name of the table you will send when it is modified
    Set xTableRg = ActiveSheet.ListObjects(xTableName).Range
    If Intersect(Target, xTableRg) Is Nothing Then Exit Sub

    Set xOutApp = CreateObject("Outlook.Application")
    Set xMailOut = xOutApp.CreateItem(olMailItem)
    For I = 1 To xTableRg.Rows.Count
        For J = 1 To xTableRg.Columns.Count
            xEmailBody = xEmailBody & "  " & xTableRg.Cells(I, J).Value
        Next
        xEmailBody = xEmailBody & vbNewLine
    Next
    xEmailBody = "Hi" & vbLf & vbLf & " body of message you want to add" & vbLf & vbLf & xEmailBody & vbNewLine
    With xMailOut
        .Subject = "Test"
        .To = ""
        .Body = xEmailBody
        .Display
        '.Send
    End With
    Set xMailOut = Nothing
    Set xOutApp = Nothing
End Sub
This comment was minimized by the moderator on the site
Hola cristal, donde dice Private Sub Worksheet_Change, deberia poner el nombre de mi excel o no?
Los rangos de (I,J) cambiarlos por los valores de celdas que yo dese estar mirando si cambian?
This comment was minimized by the moderator on the site
For me the code runs again and again, its like never ending loop. I close email it asks again to send it...
This comment was minimized by the moderator on the site
When I tried to change something in a cell a message prompted for Outlook email configuration and it just keeps on asking for my password.
This comment was minimized by the moderator on the site
Hi MJ,
Which Excel version are you using? Can you provide a screenshot of the prompt?
This comment was minimized by the moderator on the site
Sorry, I posted this in the wrong article. I will post in the correct article
This comment was minimized by the moderator on the site
Hello there, The code works great. However, when a cell changes to below the threshold point via a macro operation that copies and pastes the lower value into the designated cell, the code doesn't seem to trigger.

Also, I would like to apply this code to several cells. Can I copy and paste the code several times and change each copied version to fit each cells' needs? Is there a better way to do that. I can't figure that out. Thank you!
This comment was minimized by the moderator on the site
I copied and pasted the code exactly as-is from this page, but when I make a change to my document I get the message "Syntax Error" and this line highlights: Dim xOutApp As Object. Any help would be appreciated.
This comment was minimized by the moderator on the site
Hi Judy,
Would you provide the Excel version you are using? Thank you for your comment.
There are no comments posted here yet
Load More
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations