Gå til hovedindhold

Hvordan sendes e-mail-påmindelse eller underretning, hvis projektmappen opdateres i Excel?

I nogle tilfælde kan det være nødvendigt at udløse en e-mail-meddelelse til en bestemt modtager, hvis der er data opdateret i den projektmappe, du har sendt. Denne artikel viser dig metode til at opnå det.

Send e-mail-påmindelse eller underretning, hvis projektmappen opdateres med VBA-kode


Send e-mail-påmindelse eller underretning, hvis projektmappen opdateres med VBA-kode

Gør som følger for at sende e-mail-påmindelse eller underretning, hvis projektmappen opdateres.

1. I projektmappen skal du åbne et specificeret regneark, du vil sende e-mail-underretning baseret på de opdaterede data indeni.

2. Højreklik på arkfanen, og vælg Vis kode fra højreklikmenuen. Se skærmbillede:

2. i Microsoft Visual Basic til applikationer vindue, kopier og indsæt følgende kode i kodevinduet. Se skærmbillede:

VBA-kode: Send e-mail-påmindelse eller besked, hvis projektmappen opdateres

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

Bemærk: Erstat e-mail-adressen med modtagerens e-mail-adresse i køen .To = "E-mail-adresse". Og skift Cc, Subject såvel som body-felter i VBA-koden, som du har brug for.

3. Tryk på andre + Q taster for at lukke Microsoft Visual Basic til applikationer vindue.

4. Efter redigering af en celle i regnearket, a Kutools til Excel dialogboksen vises som vist nedenstående skærmbillede. Hvis du vil vedhæfte den opdaterede projektmappe i e-mailen, skal du klikke på Ja knap. Hvis ikke, skal du klikke på Ingen .

5. Derefter oprettes en e-mail automatisk med eller uden vedhæftet den opdaterede projektmappe. Og alle angivne felter er også angivet i e-mailen. Klik på Send knappen for at sende den.

Bemærk: VBA-koden fungerer kun, når du bruger Outlook som dit e-mail-program.


Relaterede artikler:

Bedste kontorproduktivitetsværktøjer

🤖 Kutools AI Aide: Revolutionér dataanalyse baseret på: Intelligent udførelse   |  Generer kode  |  Opret brugerdefinerede formler  |  Analyser data og generer diagrammer  |  Aktiver Kutools funktioner...
Populære funktioner: Find, fremhæv eller identificer dubletter   |  Slet tomme rækker   |  Kombiner kolonner eller celler uden at miste data   |   Runde uden formel ...
Super opslag: VLookup med flere kriterier    Multiple Value VLookup  |   VOpslag på tværs af flere ark   |   Fuzzy Lookup ....
Avanceret rulleliste: Opret hurtigt rulleliste   |  Afhængig rulleliste   |  Multivælg rulleliste ....
Column Manager: Tilføj et bestemt antal kolonner  |  Flyt kolonner  |  Skift synlighedsstatus for skjulte kolonner  |  Sammenlign områder og kolonner ...
Fremhævede funktioner: Grid fokus   |  Designvisning   |   Stor Formel Bar    Arbejdsbog & Ark Manager   |  Ressourcebibliotek (Autotekst)   |  Datovælger   |  Kombiner regneark   |  Krypter/Dekrypter celler    Send e-mails efter liste   |  Superfilter   |   Specielt filter (filter fed/kursiv/gennemstreget...) ...
Top 15 værktøjssæt12 tekst Værktøjer (tilføje tekst, Fjern tegn, ...)   |   50 + Chart Typer (Gantt kort, ...)   |   40+ Praktisk formler (Beregn alder baseret på fødselsdag, ...)   |   19 Indsættelse Værktøjer (Indsæt QR-kode, Indsæt billede fra sti, ...)   |   12 Konvertering Værktøjer (Tal til ord, Valutaomregning, ...)   |   7 Flet og del Værktøjer (Avancerede kombinere rækker, Opdel celler, ...)   |   ... og mere

Overlad dine Excel-færdigheder med Kutools til Excel, og oplev effektivitet som aldrig før. Kutools til Excel tilbyder over 300 avancerede funktioner for at øge produktiviteten og spare tid.  Klik her for at få den funktion, du har mest brug for...

Beskrivelse


Fanen Office bringer en grænseflade til et kontor med Office, og gør dit arbejde meget lettere

  • Aktiver redigering og læsning af faner i Word, Excel, PowerPoint, Publisher, Access, Visio og Project.
  • Åbn og opret flere dokumenter i nye faner i det samme vindue snarere end i nye vinduer.
  • Øger din produktivitet med 50 % og reducerer hundredvis af museklik for dig hver dag!
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