Skip i'r prif gynnwys

Sut i anfon e-bost gyda chopïo a gludo ystod benodol i'r corff e-bost yn Excel?

Mewn llawer o achosion, gallai ystod benodol o gynnwys yn nhaflen waith Excel fod yn ddefnyddiol yn eich cyfathrebiad e-bost. Yn yr erthygl hon, byddwn yn cyflwyno dull o anfon e-bost gydag pasting ystod benodol i'r corff e-bost yn uniongyrchol yn Excel.

Anfon e-bost gydag ystod benodol wedi'i gludo i'r corff e-bost yn Excel
Anfon e-bost gydag ystod benodol wedi'i gludo i mewn i gorff e-bost gydag offeryn anhygoel

Mwy o sesiynau tiwtorial ar gyfer postio yn Excel ...


Anfon e-bost gydag ystod benodol wedi'i gludo i'r corff e-bost yn Excel

Gall y cod VBA canlynol eich helpu i gopïo ystod a'i gludo i mewn i gorff e-bost Outlook yn uniongyrchol yn Excel. Gwnewch fel a ganlyn.

1. Yn y daflen waith sy'n cynnwys yr ystod y mae angen i chi ei chopïo, pwyswch y Alt + F11 allweddi ar yr un pryd i agor y Microsoft Visual Basic ar gyfer Ceisiadau ffenestr.

2. Yn yr agoriad Microsoft Visual Basic ar gyfer Ceisiadau ffenestr, cliciwch offer > Cyfeiriadau fel y dangosir isod screenshot.

3. Yn y Cyfeiriadau - VBAProject blwch deialog, dewch o hyd i a gwirio'r Llyfrgell Gwrthrychau Microsoft Outlook opsiwn, ac yna cliciwch ar y OK botwm.

4. Cliciwch Mewnosod > Modiwlau, yna copïwch a gludwch y cod VBA isod i mewn i ffenestr y Modiwl.

Cod VBA: Anfon e-bost gydag ystod benodol wedi'i gludo i'r corff e-bost yn Excel

Sub Send_Email()
'Updated by Extendoffice 20200119
    Dim xRg As Range
    Dim I, J As Long
    Dim xAddress As String
    Dim xEmailBody As String
    Dim xMailOut As Outlook.MailItem
    Dim xOutApp As Outlook.Application    
    On Error Resume Next
    xAddress = ActiveWindow.RangeSelection.Address
    Set xRg = Application.InputBox("Please select range you need to paste into email body", "KuTools For Excel", xAddress, , , , , 8)
If xRg Is Nothing Then Exit Sub
Application.ScreenUpdating = False
    Set xOutApp = CreateObject("Outlook.Application")
    Set xMailOut = xOutApp.CreateItem(olMailItem)
    For I = 1 To xRg.Rows.Count
        For J = 1 To xRg.Columns.Count
            xEmailBody = xEmailBody & "  " & xRg.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
    Application.ScreenUpdating = True
End Sub

Nodiadau:

  • 1). Newidiwch y corff e-bost yn unol xEmailBody = "Hi" & vbLf & vbLf & "corff y neges rydych chi am ei ychwanegu" & vbLf & vbLf & xEmailBody & vbNewLine fel y mae arnoch ei angen.
  • 2). Nodwch eich derbynnydd e-bost a'ch pwnc (.i= ac .Subject = "prawf") llinellau yn y cod.

5. Gwasgwch y F5 allwedd i redeg y cod. Yn y popping up Kutools ar gyfer Excel blwch deialog, dewiswch yr ystod y mae angen i chi ei gludo yn y corff e-bost, ac yna cliciwch ar y OK botwm. Gweler y screenshot:

6. Nawr bod e-bost yn cael ei greu gyda derbynnydd, pwnc, corff ac ystod Excel dethol, cliciwch ar y anfon botwm i anfon yr e-bost hwn. Gweler y screenshot a ddangosir.

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


Anfon e-bost gydag ystod benodol wedi'i gludo i mewn i gorff e-bost gydag offeryn anhygoel

Os na ddefnyddiwch Outlook ac yn dal i fod eisiau anfon e-byst yn uniongyrchol yn Excel gyda data amrediad penodol wedi'i gludo y tu mewn, rwy'n argymell y Anfon E-byst cyfleustodau Kutools ar gyfer Excel i chi. Gyda'r nodwedd hon, does ond angen i chi ffurfweddu gweinydd sy'n mynd allan o gyfeiriad e-bost, ac yna anfon e-byst yn Excel yn uniongyrchol trwy'r cyfeiriad e-bost hwn yn y dyfodol.

Cyn gwneud cais Kutools ar gyfer Excel, os gwelwch yn dda ei lawrlwytho a'i osod yn gyntaf.

1. Yn gyntaf, mae angen i chi baratoi rhestr bostio gyda'r meysydd sydd eu hangen.

  • Awgrymiadau: Rhaid i'r rhestr bostio gynnwys o leiaf 2 res, a rhaid i'r rhes gyntaf fod yn y penawdau (Gan dybio eich bod am anfon e-byst i ddau gyfeiriad e-bost yn Excel, teipiwch y ddau gyfeiriad e-bost hyn gyda'r pennawd “E-bost” fel y llun isod. ).
  • Fel arall, gallwch chi greu rhestr bostio gyda'r Creu Rhestr Bostio nodwedd.

2. Dewiswch yr ystod y byddwch chi'n ychwanegu'r data at y corff e-bost a gwasgwch y Ctrl + C allweddi i'w gopïo.

3. Dewiswch y rhestr bostio gyfan (cynnwys penawdau), cliciwch Kutools Byd Gwaith > Anfon E-byst. Gweler y screenshot:

4. Yna y Anfon E-byst blwch deialog yn ymddangos.

  • 4.1) Mae eitemau o restr bostio ddethol wedi'u poblogi mewn meysydd cyfatebol (gallwch ychwanegu mwy o feysydd at y rhestr bostio yn ôl yr angen);
  • 4.2) Cliciwch ar flwch y corff e-bost, pwyswch y Ctrl + V allweddi i gludo'r data amrediad a ddewiswyd ynddo. Ar ôl hynny, ychwanegwch gynnwys arall yn ôl yr angen;
  • 4.3 Dad-diciwch y Anfon e-byst trwy Outlook blwch;
  • 2.4) Cliciwch y Gosodiadau Gweinydd Allanol botwm. Gweler y screenshot:

5. Yna y Gosodiadau Gweinydd Allanol (SMTP) - Cynllun Newydd blwch deialog yn ymddangos. Llenwch y cyfeiriad e-bost gyda'i osodiadau gweinydd, nodwch ffolder i achub yr holl negeseuon e-bost a anfonwyd ar ôl gwirio'r Cadw e-byst a anfonwyd at blwch, ac yna cliciwch ar y OK botwm i achub y gosodiadau.

6. Pan fydd yn dychwelyd i'r Anfon E-byst blwch deialog, cliciwch y anfon botwm i anfon yr e-bost.

O hyn ymlaen, gallwch anfon e-byst gyda'r nodwedd hon yn Excel yn uniongyrchol.

  Os ydych chi am gael treial am ddim (30 diwrnod) o'r cyfleustodau hwn, cliciwch i'w lawrlwytho, ac yna ewch i gymhwyso'r llawdriniaeth yn ôl y camau uchod.


Erthyglau cysylltiedig:

Anfon e-bost i gyfeiriadau e-bost a bennir mewn celloedd yn Excel
Gan dybio bod gennych chi restr o gyfeiriadau e-bost, a'ch bod chi am anfon neges e-bost i'r cyfeiriadau e-bost hyn mewn swmp yn uniongyrchol yn Excel. Sut i'w gyflawni? Bydd yr erthygl hon yn dangos dulliau i chi o anfon e-bost i gyfeiriadau e-bost lluosog a nodwyd mewn celloedd yn Excel.

Mewnosodwch lofnod Outlook wrth anfon e-bost yn Excel
Gan dybio eich bod am anfon e-bost yn uniongyrchol yn Excel, sut allwch chi ychwanegu'r llofnod Outlook rhagosodedig yn eich e-bost? Mae'r erthygl hon yn darparu dau ddull i'ch helpu chi i ychwanegu llofnod Outlook wrth anfon e-bost yn Excel.

Anfon e-bost gydag atodiadau lluosog ynghlwm yn Excel
Mae'r erthygl hon yn sôn am anfon e-bost trwy Outlook gyda nifer o atodiadau ynghlwm yn Excel.

Anfon e-bost os yw'r dyddiad dyledus wedi'i fodloni yn Excel
Er enghraifft, os yw'r dyddiad dyledus yng ngholofn C yn llai na neu'n hafal i 7 diwrnod (y dyddiad cyfredol yw 2017/9/13), yna anfonwch nodyn atgoffa e-bost at y derbynnydd penodedig yng ngholofn A gyda chynnwys penodol yng ngholofn B. Sut i ei gyflawni? Bydd yr erthygl hon yn darparu dull VBA i ddelio ag ef yn fanwl.

Anfon e-bost yn awtomatig yn seiliedig ar werth celloedd yn Excel
Gan dybio eich bod am anfon e-bost trwy Outlook at dderbynnydd penodol yn seiliedig ar werth celloedd penodol yn Excel. Er enghraifft, pan fydd gwerth cell D7 mewn taflen waith yn fwy na 200, yna crëir e-bost yn awtomatig. Mae'r erthygl hon yn cyflwyno dull VBA i chi ddatrys y mater hwn yn gyflym.

Mwy o sesiynau tiwtorial ar gyfer postio yn Excel ...

Offer Cynhyrchiant Swyddfa Gorau

🤖 Kutools AI Aide: Chwyldro dadansoddi data yn seiliedig ar: Cyflawniad Deallus   |  Cynhyrchu Cod  |  Creu Fformiwlâu Personol  |  Dadansoddi Data a Chynhyrchu Siartiau  |  Invoke Swyddogaethau Kutools...
Nodweddion Poblogaidd: Darganfod, Amlygu neu Adnabod Dyblygiadau   |  Dileu Rhesi Gwag   |  Cyfuno Colofnau neu Gelloedd heb Colli Data   |   Rownd heb Fformiwla ...
Super-edrych: VLookup Meini Prawf Lluosog    VLookup Gwerth Lluosog  |   VLookup Ar Draws Taflenni Lluosog   |   Edrych Niwlog ....
Rhestr gwympo Uwch: Creu Rhestr Gollwng yn Gyflym   |  Rhestr Gollwng Dibynnol   |  Rhestr Gollwng Aml-ddewis ....
Rheolwr Colofn: Ychwanegu Nifer Penodol o Golofnau  |  Symud Colofnau  |  Toglo Statws Gwelededd Colofnau Cudd  |  Cymharwch Ystodau a Cholofnau ...
Nodweddion dan Sylw: Ffocws ar y Grid   |  Golwg Dylunio   |   Bar Fformiwla Mawr    Rheolwr Llyfr Gwaith a Thaflen   |  Llyfrgell Adnoddau (Testun Auto)   |  Dewiswr Dyddiad   |  Cyfuno Taflenni Gwaith   |  Amgryptio/Dadgryptio Celloedd    Anfon E-byst trwy Restr   |  Hidlo Super   |   Hidlo Arbennig (hidlo mewn print trwm/italig/strikethrough...) ...
15 Set Offer Gorau12 Testun offer (Ychwanegu Testun, Dileu Cymeriadau,...)   |   50 + Siart Mathau (Siart Gantt,...)   |   40+ Ymarferol Fformiwlâu (Cyfrifwch oedran yn seiliedig ar ben-blwydd,...)   |   19 mewnosod offer (Mewnosod Cod QR, Mewnosod Llun o'r Llwybr,...)   |   12 Trosi offer (Rhifau i Eiriau, Trosi arian cyfred,...)   |   7 Uno a Hollti offer (Rhesi Cyfuno Uwch, Celloedd Hollt,...)   |   ... a mwy

Supercharge Eich Sgiliau Excel gyda Kutools ar gyfer Excel, a Phrofiad Effeithlonrwydd Fel Erioed Erioed. Kutools ar gyfer Excel Yn Cynnig Dros 300 o Nodweddion Uwch i Hybu Cynhyrchiant ac Arbed Amser.  Cliciwch Yma i Gael Y Nodwedd Sydd Ei Angen Y Mwyaf...

Disgrifiad


Mae Office Tab yn dod â rhyngwyneb Tabbed i Office, ac yn 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!
Comments (22)
Rated 4.5 out of 5 · 1 ratings
This comment was minimized by the moderator on the site
The only issue is that the format of the table is not maintained in the mail. Can you let me know how do we preserve the format of the table in the mail, I have the same issue, could you see if you could update it please, otherwise this is excellent.
Many thanks
Rated 4.5 out of 5
This comment was minimized by the moderator on the site
Hi Andy Mitchell,
If you want to maintain the format of the table, the following VBA script can do you a favor. Please give it a try. Thank you.
Sub Send_Email()
'Updated by Extendoffice 20220616
    Dim xRg As Range
    Dim I, J As Long
    Dim xAddress As String
    Dim xMailOut As Object
    Dim xOutApp As Object
    On Error Resume Next
    Set xOutApp = CreateObject("Outlook.Application")
    Set xMailOut = xOutApp.CreateItem(olMailItem)
    xAddress = ActiveWindow.RangeSelection.Address
    Set xRg = Application.InputBox("Please select range you need to paste into email body", "KuTools For Excel", xAddress, , , , , 8)
If xRg Is Nothing Then Exit Sub
Application.ScreenUpdating = False
    Set xOutApp = CreateObject("Outlook.Application")
    Set xMailOut = xOutApp.CreateItem(olMailItem)
    With xMailOut
        .Subject = "Test"
        .To = ""
        .HTMLBody = RangetoHTML(xRg)
        .Display
        '.Send
    End With
    Set xMailOut = Nothing
    Set xOutApp = Nothing
    Application.ScreenUpdating = True
End Sub

 ' The following VBA script is cited from this page:
 ' https://stackoverflow.com/questions/18663127/paste-excel-range-in-outlook
Function RangetoHTML(rng As Range)
' By Ron de Bruin.
    Dim fso As Object
    Dim ts As Object
    Dim TempFile As String
    Dim TempWB As Workbook

    TempFile = Environ$("temp") & "/" & Format(Now, "dd-mm-yy h-mm-ss") & ".htm"

    'Copy the range and create a new workbook to past the data in
    rng.Copy
    Set TempWB = Workbooks.Add(1)
    With TempWB.Sheets(1)
        .Cells(1).PasteSpecial Paste:=8
        .Cells(1).PasteSpecial xlPasteValues, , False, False
        .Cells(1).PasteSpecial xlPasteFormats, , False, False
        .Cells(1).Select
        Application.CutCopyMode = False
        On Error Resume Next
        .DrawingObjects.Visible = True
        .DrawingObjects.Delete
        On Error GoTo 0
    End With

    'Publish the sheet to a htm file
    With TempWB.PublishObjects.Add( _
         SourceType:=xlSourceRange, _
         Filename:=TempFile, _
         Sheet:=TempWB.Sheets(1).Name, _
         Source:=TempWB.Sheets(1).UsedRange.Address, _
         HtmlType:=xlHtmlStatic)
        .Publish (True)
    End With

    'Read all data from the htm file into RangetoHTML
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set ts = fso.GetFile(TempFile).OpenAsTextStream(1, -2)
    RangetoHTML = ts.ReadAll
    ts.Close
    RangetoHTML = Replace(RangetoHTML, "align=center x:publishsource=", _
                          "align=left x:publishsource=")

    'Close TempWB
    TempWB.Close savechanges:=False

    'Delete the htm file we used in this function
    Kill TempFile

    Set ts = Nothing
    Set fso = Nothing
    Set TempWB = Nothing
End Function
This comment was minimized by the moderator on the site
This worked perfectly, thank you so much.
I can now add my spin on it to get it doing what I need.
This comment was minimized by the moderator on the site
Hi Paul Johnson,

Very happy to help you solve the problem. Have a good day at work.
This comment was minimized by the moderator on the site
hello,
can you help me on below
I have create excel sheet & updated 10 supplier mail detailI have send mail through excel to all 10 supplier with individual sheet attachment with individual mail.
I want to paste excel data in outlook body instead of attachment in mail
can any one help me
This comment was minimized by the moderator on the site
Hi,
Instead of selecting the range, I want to select multiple pivots in the excel.
can you please help me.
This comment was minimized by the moderator on the site
Hi,
Instead of selecting the range manually, I want to select the range automatically.
This comment was minimized by the moderator on the site
Hi Raman,
In the below code, please replace the range "A1:C5" in line Set xRg = Range("A1:C5") with your own range.

Sub Send_Email()
Dim xRg As Range
Dim I, J As Long
Dim xAddress As String
Dim xEmailBody As String
Dim xMailOut As Outlook.MailItem
Dim xOutApp As Outlook.Application
On Error Resume Next
xAddress = ActiveWindow.RangeSelection.Address
Set xRg = Range("A1:C5")
If xRg Is Nothing Then Exit Sub
Application.ScreenUpdating = False
Set xOutApp = CreateObject("Outlook.Application")
Set xMailOut = xOutApp.CreateItem(olMailItem)
For I = 1 To xRg.Rows.Count
For J = 1 To xRg.Columns.Count
xEmailBody = xEmailBody & " " & xRg.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
Application.ScreenUpdating = True
End Sub
This comment was minimized by the moderator on the site
Hi experts, Do we have updates on how the format maintained?
This comment was minimized by the moderator on the site
Hi Ther,
Can't figure it out. Sorry for that.
This comment was minimized by the moderator on the site
i am seeing a compile error (User-defined type not defined". Please help me out to overcome this.
This comment was minimized by the moderator on the site
Hi,
Please get into the Reference window by clicking Tools > references. Scroll down to find and check the Microsoft Outlook Object Library box and click the OK button to finish the setting.
This comment was minimized by the moderator on the site
this is pasting as a text. Kindly suggest how to send the table or the same format which is copied from the excel.
This comment was minimized by the moderator on the site
Code to send automatically after selecting after ok
This comment was minimized by the moderator on the site
Hi
This code is vary excellent, by using the code i have completed my 90% of my project.
I have same issue as mentioned by Anirudh that is table formatting. How can i format the table in email.
Please help me......
This comment was minimized by the moderator on the site
Good Day,
The problem can't be solved yet. Sorry for the inconvenience and thank you for your comment.
This comment was minimized by the moderator on the site
Hi, Is there any update on below.......
This comment was minimized by the moderator on the site
Hi, Also I Wanted code for "Filter by Date".
I am working on project, on that project I wanted to filter the data by the date, actually we have filter/hide the and last 05 days to current date data and we have highlight all other data.
Please help me to complete this project.
Your help is very great-full for me.
This comment was minimized by the moderator on the site
This is great. It is working as expected. The only issue is that the format of the table is not maintained in the mail. Can you let me know how do we preserve the format of the table in the mail
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