Ga naar hoofdinhoud

Hoe stuur ik een e-mail via Outlook wanneer de werkmap is opgeslagen in Excel?

In dit artikel wordt gesproken over het verzenden van een e-mail via Outlook wanneer een specifieke werkmap wordt opgeslagen in Excel. Doe alstublieft wat de tutorial laat zien.

Stuur een e-mail via Outlook wanneer de werkmap is opgeslagen met VBA-code


Stuur een e-mail via Outlook wanneer de werkmap is opgeslagen met VBA-code

Ga als volgt te werk om een ​​e-mail via Outlook te verzenden wanneer de werkmap is opgeslagen in Excel.

1. Sla de werkmap eerst op als een Excel-werkmap met ingeschakelde macro's. Klik Dien in > Opslaan als. In de Opslaan als dialoogvenster, selecteer een map om de werkmap op te slaan, geef deze een naam in het vak Bestandsnaam en selecteer Excel-werkmap met ingeschakelde macro's van het Opslaan als type vervolgkeuzelijst en klik vervolgens op het Bespaar knop. Zie screenshot:

2. Open de Excel-werkmap met ingeschakelde macro's die u zojuist hebt opgeslagen, druk op anders + F11 toetsen tegelijkertijd om het Microsoft Visual Basic voor toepassingen venster.

2. In de Microsoft Visual Basic voor toepassingen venster, dubbelklik Dit Werkboek in de linkerbalk en kopieer en plak de onderstaande VBA-code in het Dit Werkboek codevenster. Zie screenshot:

VBA-code: stuur een e-mail wanneer de werkmap is opgeslagen

Private Sub Workbook_AfterSave(ByVal Success As Boolean)
'Updated by Extendoffice 20181102
    Dim xOutApp As Object
    Dim xMailItem As Object
    Dim xName As String
    On Error Resume Next
    Set xOutApp = CreateObject("Outlook.Application")
    Set xMailItem = xOutApp.CreateItem(0)
    xName = ActiveWorkbook.FullName
    With xMailItem
        .To = "Email Address"
        .CC = ""
        .Subject = "The workbook has been saved"
        .Body = "Hi," & Chr(13) & Chr(13) & "File is now updated."
        .Attachments.Add xName
        .Display
       '.send
    End With
    Set xMailItem = Nothing
    Set xOutApp = Nothing
End Sub

Note: Vervang de Email adres met het e-mailadres van de ontvanger in de rij .To = "E-mailadres" en verander de Cc, het onderwerp en de body-velden in de VBA-code als je nodig hebt.

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

Vanaf nu, wanneer u de werkmap bijwerkt en opslaat, wordt automatisch een e-mail gemaakt met een bijgewerkte werkmap als bijlage. Klik op het Verzenden knop om de e-mail te verzenden. Zie screenshot:

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


Gerelateerde artikelen:

Beste Office-productiviteitstools

🤖 Kutools AI-assistent: Een revolutie teweegbrengen in de data-analyse op basis van: Intelligente uitvoering   |  Genereer code  |  Aangepaste formules maken  |  Analyseer gegevens en genereer grafieken  |  Roep Kutools-functies aan...
Populaire functies: Zoek, markeer of identificeer duplicaten   |  Verwijder lege rijen   |  Combineer kolommen of cellen zonder gegevens te verliezen   |   Ronde zonder formule ...
Super opzoeken: Meerdere criteria VLookup    VLookup met meerdere waarden  |   VOpzoeken over meerdere bladen   |   Fuzzy opzoeken ....
Geavanceerde vervolgkeuzelijst: Maak snel een vervolgkeuzelijst   |  Afhankelijke vervolgkeuzelijst   |  Multi-select vervolgkeuzelijst ....
Kolom Beheerder: Voeg een specifiek aantal kolommen toe  |  Kolommen verplaatsen  |  Schakel de zichtbaarheidsstatus van verborgen kolommen in  |  Vergelijk bereiken en kolommen ...
Uitgelichte functies: Raster focus   |  Ontwerpweergave   |   Grote formulebalk    Werkmap- en bladbeheer   |  resource Library (Auto-tekst)   |  Datumkiezer   |  Combineer werkbladen   |  Cellen coderen/decoderen    Stuur e-mails per lijst   |  Super filter   |   Speciaal filter (filter vet/cursief/doorhalen...) ...
Top 15 gereedschapsets12 Tekst Tools (toe te voegen tekst, Tekens verwijderen, ...)   |   50+ tabel Types (Gantt Chart, ...)   |   40+ Praktisch Formules (Bereken leeftijd op basis van verjaardag, ...)   |   19 Invoeging Tools (QR-code invoegen, Afbeelding invoegen vanaf pad, ...)   |   12 Camper ombouw Tools (Getallen naar woorden, Currency Conversion, ...)   |   7 Samenvoegen en splitsen Tools (Geavanceerd Combineer rijen, Gespleten cellen, ...)   |   ... en meer

Geef uw Excel-vaardigheden een boost met Kutools voor Excel en ervaar efficiëntie als nooit tevoren. Kutools voor Excel biedt meer dan 300 geavanceerde functies om de productiviteit te verhogen en tijd te besparen.  Klik hier om de functie te krijgen die u het meest nodig heeft...

Omschrijving


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 honderden muisklikken voor u elke dag!
Comments (17)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Dear All, can some one help me, I'm a novice in VBA coding, I have made some modification, but how can I do so send email if the workbook is saved, and if user name is different, like if user name of the station is glade2 then send email if the workbook is saved, else do not send.

Thank you so much for your support
This comment was minimized by the moderator on the site
Hi florin,
Didn't get your point. What does your username represent?
This comment was minimized by the moderator on the site
Hi crystal, thank you for your reply, usernane is enviroment usernane, and i have done it, i did use a if function and exit sub.
Thank you so much.
This comment was minimized by the moderator on the site
Hello - How can I include cell data in the email "cc" field?
This comment was minimized by the moderator on the site
Hi Brent,
Supposing you want to include the value in cell a7 in the email "cc" field, please try the below VBA.

Private Sub Workbook_AfterSave(ByVal Success As Boolean)

'Updated by Extendoffice 20200628

Dim xOutApp As Object

Dim xMailItem As Object

Dim xName As String

On Error Resume Next

Set xOutApp = CreateObject("Outlook.Application")

Set xMailItem = xOutApp.CreateItem(0)

xName = ActiveWorkbook.FullName

With xMailItem

.To = "Email Address"

.CC = Range("a7").Value


.Subject = "The workbook has been saved"

.Body = "Hi," & Chr(13) & Chr(13) & "File is now updated."

.Attachments.Add xName

.Display

'.send

End With

Set xMailItem = Nothing

Set xOutApp = Nothing

End Sub
This comment was minimized by the moderator on the site
Hi! Thanks a lot for this guideline :-) I would like to do something more in this code - send an email based on the countries. It means that I have to create commands with if and select. Right? I have already delete the attachment from email. I would like to add the link with path into folder instead. But when macro run, command is not valid :-(
I appreciate each help how to add it there.
This comment was minimized by the moderator on the site
Is there a way to have the automated email be auto encrypted?
This comment was minimized by the moderator on the site
Hi Mike,
Sorry can't help to solve this problem. Thank you for your comment.
This comment was minimized by the moderator on the site
How would this be handled for an Office 365 document. It is automatically saving.
This comment was minimized by the moderator on the site
Hi, nice article! One thing ive been trying to achieve with this is to attach the current state of the workbook to the email.

At the moment, it only sends the original state of the file and doesnt include any changes the user would have made.

Any ideas on how to implement this using a macro?
This comment was minimized by the moderator on the site
Hi Chris,
The code has been updated with the problem solved, please have a try. Thank you for your comment.
This comment was minimized by the moderator on the site
Hi Chris,

I have chanced upon the same issue.
Currently the codes are used in the "beforesave" module.
Which means that the email will send the spreadsheet that is before saved.

There is another module "aftersave".
I applied the code in this module and it worked like a charm.
This comment was minimized by the moderator on the site
Dear all, I would like to ask how to attach functional link to certain folder on server, if I paste the link, it appears in the workbook just like plain text and so it doensn't work in received e-mail, how can I turn it into link, so recepiants can click on it?
I would like to use this way instead sending enclosed excel file.
Thanks for advice
This comment was minimized by the moderator on the site
I put this in the body of the email and it worked for me...
"file:///Z:\dir1\dir2\dir3\Test1.xlsm"
This comment was minimized by the moderator on the site
Hi Robert,
Sorry can’t help with this, welcome to post any question about Excel to our forum: https://www.extendoffice.com/forum.html. You will get more Excel supports from our professional or other Excel fans.
This comment was minimized by the moderator on the site
Gracias. Consulta: utilizando esta misma rutina, como podría enviar el correo a un correo específico dependiendo el valor de otra celda?
This comment was minimized by the moderator on the site
How to automate the email notification in VBA based on Date range, without having to see the pop up for security permission to allow VBA to send the email.
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations