Ugrás a tartalomra

Hogyan küldhetünk e-mailt az Outlookon keresztül, amikor a munkafüzet mentésre kerül az Excelbe?

Ez a cikk arról szól, hogy e-mailt küldjön az Outlook segítségével, amikor egy adott munkafüzet mentésre kerül az Excel programba. Kérjük, tegye meg, ahogy a bemutató mutatja.

Küldjön e-mailt az Outlookon keresztül, amikor a munkafüzetet VBA kóddal menti


Küldjön e-mailt az Outlookon keresztül, amikor a munkafüzetet VBA kóddal menti

Ha a munkafüzet mentése az Excel-be az e-mailen keresztül történik, kérjük, tegye a következőket.

1. Először kérjük, mentse el a munkafüzetet Excel makróképes munkafüzetként. Kattintson a gombra filé > Mentés másként. Az Mentés másként párbeszédpanelen válasszon egy mappát a munkafüzet mentéséhez, nevezze el a Fájlnév mezőben, majd válassza a lehetőséget Excel makró-engedélyezett munkafüzet tól Mentés típus legördülő listára, majd kattintson a gombra Megtakarítás gomb. Lásd a képernyőképet:

2. Nyissa meg az imént mentett Excel makró-engedélyezett munkafüzetet, nyomja meg a gombot más + F11 gombok egyszerre a Microsoft Visual Basic for Applications ablak.

2. Ban,-ben Microsoft Visual Basic for Applications ablak, kattintson duplán Ez a munkafüzet a bal sávban, majd másolja és illessze be az alábbi VBA kódot a Ez a munkafüzet kód ablak. Lásd a képernyőképet:

VBA kód: E-mail küldése a munkafüzet mentésekor

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

Megjegyzések: Kérjük, cserélje ki a E-mail címe a címzett e-mail címével a sorban .To = "E-mail cím"és szükség szerint módosítsa a Vc kódban a Cc, Subject és a body mezőket.

3. megnyomni a más + Q gombok egyszerre a Microsoft Visual Basic for Applications ablak.

Mostantól a munkafüzet frissítésekor és mentésekor automatikusan létrejön egy e-mail, mellékelve a frissített munkafüzettel. Kattintson a gombra Küldés gombra az e-mail elküldéséhez. Lásd a képernyőképet:

Megjegyzések: A VBA kód csak akkor működik, ha az Outlook programot használja e-mail programként.


Kapcsolódó cikkek:

A legjobb irodai hatékonyságnövelő eszközök

🤖 Kutools AI Aide: Forradalmasítsa az adatelemzést a következők alapján: Intelligens végrehajtás   |  Kód létrehozása  |  Hozzon létre egyéni képleteket  |  Adatok elemzése és diagramok létrehozása  |  A Kutools funkciók meghívása...
Népszerű szolgáltatások: Ismétlődések keresése, kiemelése vagy azonosítása   |  Üres sorok törlése   |  Oszlopok vagy cellák kombinálása adatvesztés nélkül   |   Kerek Formula nélkül ...
Szuper keresés: Több kritérium VLookup    Többértékű VLookup  |   VLookup több munkalapon   |   Fuzzy Lookup ....
Speciális legördülő lista: Gyors legördülő lista létrehozása   |  Függő legördülő lista   |  Többszörösen válassza ki a legördülő listát ....
Oszlopkezelő: Adjon meg egy adott számú oszlopot  |  Oszlopok mozgatása  |  Kapcsolja be a Rejtett oszlopok láthatósági állapotát  |  Tartományok és oszlopok összehasonlítása ...
Kiemelt funkciók: Rács fókusz   |  Design nézet   |   Nagy Formula bár    Munkafüzet és lapkezelő   |  Erőforrás-könyvtár (Auto szöveg)   |  Dátumválasztó   |  Kombinálja a munkalapokat   |  Cellák titkosítása/dekódolása    E-mailek küldése listánként   |  Szuper szűrő   |   Speciális szűrő (félkövér/dőlt/áthúzott szűrés...) ...
A 15 legjobb eszközkészlet12 szöveg Eszközök (Szöveg hozzáadása, Karakterek eltávolítása,...)   |   50 + Táblázatos Típusai (Gantt-diagram,...)   |   40+ Praktikus képletek (Számolja ki az életkort a születésnap alapján,...)   |   19 beszúrás Eszközök (Helyezze be a QR-kódot, Kép beszúrása az útvonalból,...)   |   12 Átalakítás Eszközök (Számok szavakig, Valuta átváltás,...)   |   7 Egyesítés és felosztás Eszközök (Haladó kombinált sorok, Hasított sejtek,...)   |   ... és több

Töltsd fel Excel-készségeidet a Kutools for Excel segítségével, és tapasztald meg a még soha nem látott hatékonyságot. A Kutools for Excel több mint 300 speciális funkciót kínál a termelékenység fokozásához és az időmegtakarításhoz.  Kattintson ide, hogy megszerezze a leginkább szükséges funkciót...

Leírás


Az Office lap füles felületet hoz az Office-ba, és sokkal könnyebbé teszi a munkáját

  • Füles szerkesztés és olvasás engedélyezése Wordben, Excelben és PowerPointban, Publisher, Access, Visio és Project.
  • Több dokumentum megnyitása és létrehozása ugyanazon ablak új lapjain, mint új ablakokban.
  • 50% -kal növeli a termelékenységet, és naponta több száz kattintással csökkenti az egér kattintását!
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