Note: The other languages of the website are Google-translated. Back to English
Mewngofnodi  \/ 
x
or
x
Cofrestru  \/ 
x

or

Sut i anfon e-bost trwy Outlook pan arbedir llyfr gwaith yn Excel?

Mae'r erthygl hon yn sôn am anfon e-bost trwy Outlook pan arbedir llyfr gwaith penodol yn Excel. Gwnewch fel y dengys y tiwtorial.

Anfonwch e-bost trwy Outlook pan arbedir llyfr gwaith gyda chod VBA


Anfonwch e-bost trwy Outlook pan arbedir llyfr gwaith gyda chod VBA


Ar gyfer anfon e-bost trwy Outlook pan fydd y llyfr gwaith yn cael ei gadw yn Excel, gwnewch fel a ganlyn.

1. Cadwch y llyfr gwaith fel Llyfr Gwaith Macro-alluog Excel ar y dechrau. Cliciwch ffeil > Save As. Yn y Save As blwch deialog, dewiswch ffolder i achub y llyfr gwaith, ei enwi yn y blwch enw Ffeil, dewiswch Llyfr Gwaith Macro-alluogedig Excel oddi wrth y Cadw fel math rhestr ostwng, ac yna cliciwch ar y Save botwm. Gweler y screenshot:

2. Agorwch y Llyfr Gwaith Macro-alluog Excel rydych chi wedi'i arbed nawr, pwyswch y Alt + F11 allweddi ar yr un pryd i agor y Microsoft Visual Basic ar gyfer Ceisiadau ffenestr.

2. Yn y Microsoft Visual Basic ar gyfer Ceisiadau ffenestr, cliciwch ddwywaith Llyfr Gwaith hwn yn y bar chwith, yna copïwch a gludwch y cod VBA isod i'r Llyfr Gwaith hwn ffenestr cod. Gweler y screenshot:

Cod VBA: Anfon e-bost pan arbedir llyfr gwaith

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

Nodyn: Amnewid y e-bost Cyfeiriad gyda'r cyfeiriad e-bost derbynnydd yn unol .To = "Cyfeiriad E-bost", a newid y Cc, Pwnc yn ogystal â meysydd y corff yn y cod VBA yn ôl yr angen.

3. Gwasgwch y Alt + Q allweddi ar yr un pryd i gau'r Microsoft Visual Basic ar gyfer Ceisiadau ffenestr.

O hyn ymlaen, pan fyddwch chi'n diweddaru'r llyfr gwaith a'i gadw, bydd e-bost yn cael ei greu'n awtomatig gyda'r llyfr gwaith wedi'i ddiweddaru ynghlwm. Cliciwch y anfon botwm i anfon yr e-bost. Gweler y screenshot:

Nodyn: Dim ond pan fyddwch chi'n defnyddio Outlook fel eich rhaglen e-bost y mae'r cod VBA yn gweithio.


Erthyglau cysylltiedig:


Yr Offer Cynhyrchedd Swyddfa Gorau

Mae Kutools for Excel yn Datrys y rhan fwyaf o'ch Problemau, ac yn Cynyddu Eich Cynhyrchedd 80%

  • Ailddefnyddio: Mewnosod yn gyflym fformwlâu cymhleth, siartiau ac unrhyw beth rydych chi wedi'i ddefnyddio o'r blaen; Amgryptio Celloedd gyda chyfrinair; Creu Rhestr Bostio ac anfon e-byst ...
  • Bar Fformiwla Gwych (golygu llinellau lluosog o destun a fformiwla yn hawdd); Cynllun Darllen (darllen a golygu nifer fawr o gelloedd yn hawdd); Gludo i'r Ystod Hidlo...
  • Uno Celloedd / Rhesi / Colofnau heb golli Data; Cynnwys Celloedd Hollt; Cyfuno Rhesi / Colofnau Dyblyg... Atal Celloedd Dyblyg; Cymharwch y Meysydd...
  • Dewiswch Dyblyg neu Unigryw Rhesi; Dewiswch Blank Rows (mae pob cell yn wag); Darganfyddiad Gwych a Darganfyddiad Niwlog mewn Llawer o Lyfrau Gwaith; Dewis ar Hap ...
  • Copi Union Celloedd Lluosog heb newid cyfeirnod fformiwla; Auto Creu Cyfeiriadau i Daflenni Lluosog; Mewnosod Bwledi, Blychau Gwirio a mwy ...
  • Testun Detholiad, Ychwanegu Testun, Tynnu yn ôl Swydd, Tynnwch y Gofod; Creu ac Argraffu Subtotals Paging; Trosi rhwng Cynnwys a Sylwadau Celloedd...
  • Hidlo Super (arbed a chymhwyso cynlluniau hidlo i ddalenni eraill); Trefnu Uwch yn ôl mis / wythnos / dydd, amlder a mwy; Hidlo Arbennig gan feiddgar, italig ...
  • Cyfuno Llyfrau Gwaith a Thaflenni Gwaith; Uno Tablau yn seiliedig ar golofnau allweddol; Rhannwch Ddata yn Daflenni Lluosog; Trosi Swp xls, xlsx a PDF...
  • Mwy na 300 o nodweddion pwerus. Yn cefnogi Swyddfa / Excel 2007-2019 a 365. Yn cefnogi pob iaith. Defnydd hawdd yn eich menter neu sefydliad. Nodweddion llawn treial am ddim 30 diwrnod. Gwarant arian yn ôl 60 diwrnod.
tab kte 201905

Mae Tab Office yn Dod â rhyngwyneb Tabbed i'r Swyddfa, a Gwneud Eich Gwaith yn Haws o lawer

  • Galluogi golygu a darllen tabbed yn Word, Excel, PowerPoint, Cyhoeddwr, Mynediad, Visio a Phrosiect.
  • Agor a chreu dogfennau lluosog mewn tabiau newydd o'r un ffenestr, yn hytrach nag mewn ffenestri newydd.
  • Yn cynyddu eich cynhyrchiant 50%, ac yn lleihau cannoedd o gliciau llygoden i chi bob dydd!
gwaelod officetab
Say something here...
symbols left.
You are guest
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    florin · 1 years ago
    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
    • To post as a guest, your comment is unpublished.
      crystal · 1 years ago
      Hi florin,
      Didn't get your point. What does your username represent?
      • To post as a guest, your comment is unpublished.
        Florin Dan · 1 years ago
        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.
  • To post as a guest, your comment is unpublished.
    Brent · 1 years ago
    Hello - How can I include cell data in the email "cc" field?
    • To post as a guest, your comment is unpublished.
      crystal · 1 years ago
      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
  • To post as a guest, your comment is unpublished.
    Lena · 1 years ago
    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.
  • To post as a guest, your comment is unpublished.
    Mike · 2 years ago
    Is there a way to have the automated email be auto encrypted?
    • To post as a guest, your comment is unpublished.
      crystal · 2 years ago
      Hi Mike,
      Sorry can't help to solve this problem. Thank you for your comment.
  • To post as a guest, your comment is unpublished.
    mayle4pam · 2 years ago
    How would this be handled for an Office 365 document. It is automatically saving.
  • To post as a guest, your comment is unpublished.
    Chris · 3 years ago
    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?
    • To post as a guest, your comment is unpublished.
      crystal · 2 years ago
      Hi Chris,
      The code has been updated with the problem solved, please have a try. Thank you for your comment.
      • To post as a guest, your comment is unpublished.
        Tin Hwee Lee · 2 years ago
        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.
  • To post as a guest, your comment is unpublished.
    Bob · 3 years ago
    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
    • To post as a guest, your comment is unpublished.
      Grant · 2 years ago
      I put this in the body of the email and it worked for me...
      "file:///Z:\dir1\dir2\dir3\Test1.xlsm"
    • To post as a guest, your comment is unpublished.
      crystal · 3 years ago
      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.
  • To post as a guest, your comment is unpublished.
    Antonio · 3 years ago
    Gracias. Consulta: utilizando esta misma rutina, como podría enviar el correo a un correo específico dependiendo el valor de otra celda?
  • To post as a guest, your comment is unpublished.
    Jermaine · 3 years ago
    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.