Μετάβαση στο κύριο περιεχόμενο

Πώς να στείλετε ένα email μέσω του Outlook όταν το βιβλίο εργασίας είναι αποθηκευμένο στο Excel;

Αυτό το άρθρο αφορά την αποστολή email μέσω του Outlook όταν ένα συγκεκριμένο βιβλίο εργασίας αποθηκεύεται στο Excel. Κάντε το όπως δείχνει το σεμινάριο.

Στείλτε ένα email μέσω του Outlook όταν το βιβλίο εργασίας αποθηκεύεται με κωδικό VBA


Στείλτε ένα email μέσω του Outlook όταν το βιβλίο εργασίας αποθηκεύεται με κωδικό VBA

Για την αποστολή email μέσω του Outlook όταν το βιβλίο εργασίας είναι αποθηκευμένο στο Excel, κάντε τα εξής.

1. Αποθηκεύστε πρώτα το βιβλίο εργασίας ως βιβλίο εργασίας με δυνατότητα Macro-Enabled. Κάντε κλικ Αρχεία > Αποθήκευση ως. Στην Αποθήκευση ως πλαίσιο διαλόγου, επιλέξτε ένα φάκελο για αποθήκευση του βιβλίου εργασίας, ονομάστε το στο πλαίσιο Όνομα αρχείου, επιλέξτε Βιβλίο εργασίας Excel με δυνατότητα μακροεντολής από το Αποθήκευση ως τύπου αναπτυσσόμενη λίστα και, στη συνέχεια, κάντε κλικ στο Αποθήκευση κουμπί. Δείτε το στιγμιότυπο οθόνης:

2. Ανοίξτε το βιβλίο εργασίας του Excel με δυνατότητα μακροεντολής που έχετε αποθηκεύσει μόλις τώρα, πατήστε το άλλος + F11 ταυτόχρονα για να ανοίξετε το Microsoft Visual Basic για εφαρμογές παράθυρο.

2. Στο Microsoft Visual Basic για εφαρμογές κάντε διπλό κλικ Αυτό το βιβλίο εργασίας στην αριστερή γραμμή και, στη συνέχεια, αντιγράψτε και επικολλήστε τον παρακάτω κώδικα VBA στο Αυτό το βιβλίο εργασίας παράθυρο κώδικα. Δείτε το στιγμιότυπο οθόνης:

Κωδικός VBA: Αποστολή email όταν αποθηκεύεται το βιβλίο εργασίας

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: Παρακαλώ αντικαταστήστε το Διεύθυνση ηλεκτρονικού ταχυδρομείου με τη διεύθυνση email του παραλήπτη στη γραμμή .To = "Διεύθυνση ηλεκτρονικού ταχυδρομείου", να αλλάξτε τα πεδία Cc, Subject και body στον κώδικα VBA όπως χρειάζεστε.

3. Πάτα το άλλος + Q ταυτόχρονα για να κλείσετε το Microsoft Visual Basic για εφαρμογές παράθυρο.

Από τώρα και στο εξής, όταν ενημερώνετε το βιβλίο εργασίας και το αποθηκεύετε, θα δημιουργηθεί αυτόματα ένα μήνυμα ηλεκτρονικού ταχυδρομείου με συνημμένο το ενημερωμένο βιβλίο εργασίας. Κάντε κλικ στο Αποστολή κουμπί για να στείλετε το email. Δείτε το στιγμιότυπο οθόνης:

Note: Ο κωδικός VBA λειτουργεί μόνο όταν χρησιμοποιείτε το Outlook ως πρόγραμμα ηλεκτρονικού ταχυδρομείου.


Σχετικά άρθρα:

Τα καλύτερα εργαλεία παραγωγικότητας γραφείου

🤖 Kutools AI Aide: Επανάσταση στην ανάλυση δεδομένων με βάση: Ευφυής Εκτέλεση   |  Δημιουργία κώδικα  |  Δημιουργία προσαρμοσμένων τύπων  |  Αναλύστε δεδομένα και δημιουργήστε γραφήματα  |  Επίκληση Λειτουργιών Kutools...
Δημοφιλή χαρακτηριστικά: Εύρεση, επισήμανση ή αναγνώριση διπλότυπων   |  Διαγραφή κενών γραμμών   |  Συνδυάστε στήλες ή κελιά χωρίς απώλεια δεδομένων   |   Γύρος χωρίς φόρμουλα ...
Σούπερ Αναζήτηση: VLookup πολλαπλών κριτηρίων    VLookup πολλαπλών τιμών  |   VLookup σε πολλά φύλλα   |   Ασαφής αναζήτηση ....
Σύνθετη αναπτυσσόμενη λίστα: Γρήγορη δημιουργία αναπτυσσόμενης λίστας   |  Εξαρτημένη αναπτυσσόμενη λίστα   |  Πολλαπλή αναπτυσσόμενη λίστα ....
Διαχειριστής στήλης: Προσθέστε έναν συγκεκριμένο αριθμό στηλών  |  Μετακίνηση στηλών  |  Εναλλαγή κατάστασης ορατότητας κρυφών στηλών  |  Συγκρίνετε εύρη και στήλες ...
Επιλεγμένα Χαρακτηριστικά: Εστίαση πλέγματος   |  Προβολή σχεδίου   |   Μεγάλη Formula Bar    Διαχείριση βιβλίου εργασίας & φύλλου   |  Βιβλιοθήκη πόρων (Αυτόματο κείμενο)   |  Επιλογή ημερομηνίας   |  Συνδυάστε φύλλα εργασίας   |  Κρυπτογράφηση/Αποκρυπτογράφηση κελιών    Αποστολή email ανά λίστα   |  Σούπερ φίλτρο   |   Ειδικό φίλτρο (φίλτρο με έντονη γραφή/πλάγια γραφή/διαγραφή...) ...
Κορυφαία 15 σύνολα εργαλείων12 Κείμενο Εργαλεία (Προσθήκη κειμένου, Κατάργηση χαρακτήρων, ...)   |   50 + Διάγραμμα Τύποι (Gantt διάγραμμα, ...)   |   40+ Πρακτικό ΜΑΘΗΜΑΤΙΚΟΙ τυποι (Υπολογίστε την ηλικία με βάση τα γενέθλια, ...)   |   19 Εισαγωγή Εργαλεία (Εισαγωγή κωδικού QR, Εισαγωγή εικόνας από το μονοπάτι, ...)   |   12 Μετατροπή Εργαλεία (Αριθμοί σε λέξεις, Μετατροπή Συναλλάγματος, ...)   |   7 Συγχώνευση & διαχωρισμός Εργαλεία (Σύνθετες σειρές συνδυασμού, Διαίρεση κελιών, ...)   |   ... κι αλλα

Αυξήστε τις δεξιότητές σας στο Excel με τα Kutools για Excel και απολαύστε την αποτελεσματικότητα όπως ποτέ πριν. Το Kutools για Excel προσφέρει πάνω από 300 προηγμένες δυνατότητες για την ενίσχυση της παραγωγικότητας και την εξοικονόμηση χρόνου.  Κάντε κλικ εδώ για να αποκτήσετε τη δυνατότητα που χρειάζεστε περισσότερο...

Περιγραφή


Το Office Tab φέρνει τη διεπαφή με καρτέλες στο Office και κάνει την εργασία σας πολύ πιο εύκολη

  • Ενεργοποίηση επεξεργασίας και ανάγνωσης καρτελών σε Word, Excel, PowerPoint, Publisher, Access, Visio και Project.
  • Ανοίξτε και δημιουργήστε πολλά έγγραφα σε νέες καρτέλες του ίδιου παραθύρου και όχι σε νέα παράθυρα.
  • Αυξάνει την παραγωγικότητά σας κατά 50% και μειώνει εκατοντάδες κλικ του ποντικιού για εσάς κάθε μέρα!
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