Vai al contenuto principale

Come inviare e-mail copiando e incollando un intervallo specificato nel corpo dell'e-mail in Excel?

In molti casi, un intervallo di contenuti specificato nel foglio di lavoro di Excel può essere utile nella comunicazione e-mail. In questo articolo, introdurremo un metodo per inviare un'e-mail con un intervallo specificato incollato nel corpo dell'e-mail direttamente in Excel.

Invia e-mail con un intervallo specificato incollato nel corpo dell'e-mail in Excel
Invia e-mail con un intervallo specificato incollato nel corpo dell'e-mail con uno strumento straordinario

Altri tutorial per l'invio di posta in Excel ...


Invia e-mail con un intervallo specificato incollato nel corpo dell'e-mail in Excel

Il seguente codice VBA può aiutarti a copiare un intervallo e incollarlo nel corpo di un messaggio di posta elettronica di Outlook direttamente in Excel. Si prega di fare quanto segue.

1. Nel foglio di lavoro contiene l'intervallo che è necessario copiare, premere il tasto altro + F11 tasti contemporaneamente per aprire il file Microsoft Visual Basic, Applications Edition finestra.

2. In apertura Microsoft Visual Basic, Applications Edition finestra, fare clic Strumenti > Riferimenti come mostrato nell'immagine sottostante.

3. Nel Riferimenti - VBAProject finestra di dialogo, trova e controlla il file Libreria di oggetti di Microsoft Outlook opzione, quindi fare clic su OK pulsante.

4. Clic inserire > Moduli, quindi copia e incolla il codice VBA sottostante nella finestra del modulo.

Codice VBA: invia e-mail con un intervallo specificato incollato nel corpo dell'e-mail in 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

Note:

  • 1). Si prega di modificare il corpo dell'email in linea xEmailBody = "Ciao" & vbLf & vbLf & "corpo del messaggio che desideri aggiungere" & vbLf & vbLf & xEmailBody & vbNewLine di cui hai bisogno.
  • 2). Si prega di specificare il destinatario e l'oggetto dell'e-mail (.A = ed .Subject = "test") righe nel codice.

5. premi il F5 chiave per eseguire il codice. Nel spuntare Kutools for Excel finestra di dialogo, selezionare l'intervallo che è necessario incollare nel corpo dell'e-mail, quindi fare clic su OK pulsante. Vedi screenshot:

6. Ora viene creata un'e-mail con il destinatario, l'oggetto, il corpo e l'intervallo di Excel selezionati specificati, fare clic su Invia pulsante per inviare questa email. Vedi screenshot mostrato.

Note:: Il codice VBA funziona solo quando utilizzi Outlook come programma di posta elettronica.


Invia e-mail con un intervallo specificato incollato nel corpo dell'e-mail con uno strumento straordinario

Se non utilizzi Outlook e desideri comunque inviare e-mail direttamente in Excel con un intervallo specificato di dati incollati all'interno, consiglio vivamente il Inviare emails utilità di Kutools for Excel per te. Con questa funzione, devi solo configurare il server in uscita di un indirizzo e-mail, quindi inviare e-mail in Excel direttamente tramite questo indirizzo e-mail in futuro.

Prima di applicare Kutools for Excel, Per favore scaricalo e installalo prima.

1. In primo luogo, è necessario preparare una mailing list con i campi necessari.

  • Suggerimenti:: La mailing list deve contenere almeno 2 righe e la prima riga deve essere le intestazioni (supponendo che si desideri inviare e-mail a due indirizzi e-mail in Excel, digitare questi due indirizzi e-mail con l'intestazione "E-mail" come mostrato nell'immagine sottostante ).
  • In alternativa, puoi creare facilmente una mailing list con l'estensione Crea mailing list caratteristica.

2. Selezionare l'intervallo in cui aggiungere i dati al corpo dell'email e premere il tasto Ctrl + C chiavi per copiarlo.

3. Selezionare l'intera mailing list (includi intestazioni), fare clic su Kutools Plus > Inviare emails. Vedi screenshot:

4. Quindi il file Inviare emails si apre la finestra di dialogo.

  • 4.1) Gli elementi della mailing list selezionata vengono popolati nei campi corrispondenti (puoi aggiungere più campi alla mailing list di cui hai bisogno);
  • 4.2) Fare clic sulla casella del corpo dell'email, premere il pulsante Ctrl + V tasti per incollare al suo interno i dati dell'intervallo selezionato. Successivamente, aggiungi altri contenuti di cui hai bisogno;
  • 4.3 Deseleziona il Invia email tramite Outlook scatola;
  • 2.4) Fare clic su Impostazioni del server in uscita pulsante. Vedi screenshot:

5. Quindi il file Impostazioni server in uscita (SMTP) - Nuovo schema si apre la finestra di dialogo. Si prega di inserire l'indirizzo e-mail con le impostazioni del server, specificare una cartella in cui salvare tutte le e-mail inviate dopo aver controllato il file Salva le email inviate a casella, quindi fare clic su OK pulsante per salvare le impostazioni.

6. Quando ritorna al file Inviare emails finestra di dialogo, fare clic su Invia pulsante per inviare l'email.

D'ora in poi, puoi inviare e-mail con questa funzione direttamente in Excel.

  Se desideri avere una prova gratuita (30 giorni) di questa utility, fare clic per scaricarlo, quindi andare ad applicare l'operazione secondo i passaggi precedenti.


Articoli correlati:

Invia e-mail agli indirizzi e-mail specificati nelle celle in Excel
Supponendo che tu abbia un elenco di indirizzi e-mail e desideri inviare messaggi e-mail a questi indirizzi in blocco direttamente in Excel. Come ottenerlo? Questo articolo ti mostrerà i metodi per inviare e-mail a più indirizzi e-mail specificati nelle celle in Excel.

Inserisci la firma di Outlook durante l'invio di e-mail in Excel
Supponendo che tu voglia inviare un'e-mail direttamente in Excel, come puoi aggiungere la firma predefinita di Outlook nell'e-mail? Questo articolo fornisce due metodi per aiutarti ad aggiungere la firma di Outlook quando invii messaggi di posta elettronica in Excel.

Invia e-mail con più allegati allegati in Excel
Questo articolo parla dell'invio di un'e-mail tramite Outlook con più allegati allegati in Excel.

Invia e-mail se la data di scadenza è stata rispettata in Excel
Ad esempio, se la data di scadenza nella colonna C è inferiore o uguale a 7 giorni (la data corrente è 2017/9/13), inviare un promemoria e-mail al destinatario specificato nella colonna A con il contenuto specificato nella colonna B. Procedura raggiungerlo? Questo articolo fornirà un metodo VBA per affrontarlo in dettaglio.

Invia automaticamente e-mail in base al valore della cella in Excel
Supponendo di voler inviare un'e-mail tramite Outlook a un determinato destinatario in base a un valore di cella specificato in Excel. Ad esempio, quando il valore della cella D7 in un foglio di lavoro è maggiore di 200, viene creata automaticamente un'e-mail. Questo articolo introduce un metodo VBA per risolvere rapidamente questo problema.

Altri tutorial per l'invio di posta in Excel ...

I migliori strumenti per la produttività in ufficio

🤖 Assistente AI di Kutools: Rivoluziona l'analisi dei dati basandosi su: Esecuzione intelligente   |  Genera codice  |  Crea formule personalizzate  |  Analizzare i dati e generare grafici  |  Richiama le funzioni di Kutools...
Funzioni popolari: Trova, evidenzia o identifica i duplicati   |  Elimina righe vuote   |  Combina colonne o celle senza perdere dati   |   Round senza formula ...
Super ricerca: VLookup a criteri multipli    VLookup a valori multipli  |   VLookup su più fogli   |   Ricerca fuzzy ....
Elenco a discesa avanzato: Crea rapidamente un elenco a discesa   |  Elenco a discesa dipendente   |  Elenco a discesa a selezione multipla ....
Gestore di colonna: Aggiungi un numero specifico di colonne  |  Sposta colonne  |  Attiva/disattiva lo stato di visibilità delle colonne nascoste  |  Confronta intervalli e colonne ...
Funzionalità in primo piano: Messa a fuoco della griglia   |  Vista di progettazione   |   Grande barra delle formule    Gestore di cartelle di lavoro e fogli   |  Resource Library (Testo automatico)   |  Date picker   |  Combina fogli di lavoro   |  Crittografa/decrittografa le celle    Invia e-mail per elenco   |  Super filtro   |   Filtro speciale (filtro grassetto/corsivo/barrato...) ...
I 15 migliori set di strumenti12 Testo Strumenti (aggiungi testo, Rimuovi personaggi, ...)   |   50+ Grafico Tipi (Diagramma di Gantt, ...)   |   40+ Pratico Formule (Calcola l'età in base al compleanno, ...)   |   19 Inserimento Strumenti (Inserisci il codice QR, Inserisci immagine dal percorso, ...)   |   12 Conversione Strumenti (Numeri in parole, Conversione di valuta, ...)   |   7 Unisci e dividi Strumenti (Combina righe avanzate, Celle divise, ...)   |   ... e altro ancora

Potenzia le tue competenze di Excel con Kutools per Excel e sperimenta l'efficienza come mai prima d'ora. Kutools per Excel offre oltre 300 funzionalità avanzate per aumentare la produttività e risparmiare tempo.  Fai clic qui per ottenere la funzionalità di cui hai più bisogno...

Descrizione


Office Tab porta l'interfaccia a schede in Office e semplifica notevolmente il tuo lavoro

  • Abilita la modifica e la lettura a schede in Word, Excel, PowerPoint, Publisher, Access, Visio e Project.
  • Apri e crea più documenti in nuove schede della stessa finestra, piuttosto che in nuove finestre.
  • Aumenta la produttività del 50% e riduce ogni giorno centinaia di clic del mouse!
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