Vai al contenuto principale

Come inviare / inviare per e-mail un intervallo di celle tramite Outlook da Excel?

Hai mai sofferto di un problema dopo aver terminato un rapporto in un foglio di lavoro e devi inviare a un intervallo di celle in questo foglio di lavoro che contengono alcuni dati importanti per il tuo destinatario specifico. Esistono modi rapidi per inviare tramite posta elettronica questo intervallo da Excel senza aprire Outlook?

Invia intervallo di celle come allegato da Excel con codice VBA

Invia intervallo di celle come corpo da Excel con codice VBA


freccia blu freccia destraInvia intervallo di celle come allegato da Excel con codice VBA

Il seguente codice VBA può aiutarti a inviare l'intervallo selezionato come allegato in Excel. Per favore, fai come segue:

1. Apri la cartella di lavoro e quindi tieni premuto il pulsante ALT + F11 chiavi per aprire il Finestra di Microsoft Visual Basic, Applications Edition.

2. Clic inserire > Modulie incolla il codice seguente nel file Finestra del modulo.

Codice VBA: invia intervallo di celle come allegato da Excel

Sub SendRange()
'Update 20131209
Dim xFile As String
Dim xFormat As Long
Dim Wb As Workbook
Dim Wb2 As Workbook
Dim Ws As Worksheet
Dim FilePath As String
Dim FileName As String
Dim OutlookApp As Object
Dim OutlookMail As Object
Dim WorkRng As Range
xTitleId = "KutoolsforExcel"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set Wb = Application.ActiveWorkbook
Wb.Worksheets.Add
Set Ws = Application.ActiveSheet
WorkRng.Copy Ws.Cells(1, 1)
Ws.Copy
Set Wb2 = Application.ActiveWorkbook
Select Case Wb.FileFormat
Case xlOpenXMLWorkbook:
    xFile = ".xlsx"
    xFormat = xlOpenXMLWorkbook
Case xlOpenXMLWorkbookMacroEnabled:
    If Wb2.HasVBProject Then
        xFile = ".xlsm"
        xFormat = xlOpenXMLWorkbookMacroEnabled
    Else
        xFile = ".xlsx"
        xFormat = xlOpenXMLWorkbook
    End If
Case Excel8:
    xFile = ".xls"
    xFormat = Excel8
Case xlExcel12:
    xFile = ".xlsb"
    xFormat = xlExcel12
End Select
FilePath = Environ$("temp") & "\"
FileName = Wb.Name & Format(Now, "dd-mmm-yy h-mm-ss")
Set OutlookApp = CreateObject("Outlook.Application")
Set OutlookMail = OutlookApp.CreateItem(0)
Wb2.SaveAs FilePath & FileName & xFile, FileFormat:=xFormat
With OutlookMail
    .To = ""
    .CC = ""
    .BCC = ""
    .Subject = "information of kte"
    .Body = "hello, please check and read this document. "
    .Attachments.Add Wb2.FullName
    .Send
End With
Wb2.Close
Kill FilePath & FileName & xFile
Set OutlookMail = Nothing
Set OutlookApp = Nothing
Ws.Delete
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub

Note:: Nel codice sopra, puoi modificare le seguenti informazioni in base alle tue esigenze.

  • .A = ""
  • .CC = ""
  • .BCC = ""
  • .Subject = "informazioni su kte"
  • .Body = "ciao, controlla e leggi questo documento."

3. Quindi fare clic F5 chiave per eseguire questo codice e verrà visualizzata una finestra di messaggio per ricordarti di selezionare un intervallo che desideri inviare. Vedi screenshot:

doc-send-range1

4. Quindi fare clic OKe verrà visualizzata una finestra di messaggio, al termine della barra di avanzamento, fare clic su Consentiree quindi l'intervallo specifico di celle è stato inviato al destinatario come allegato.

doc-send-range2


freccia blu freccia destraInvia intervallo di celle come corpo da Excel con codice VBA

Se desideri inviare un intervallo specifico come parte del corpo del messaggio da Excel, puoi anche applicare il seguente codice VBA per risolverlo.

Kutools for Excel, con oltre 120 funzioni utili, semplifica il tuo lavoro. 

1. Attiva il foglio di lavoro e tieni premuto il tasto ALT + F11 chiavi per aprire il Finestra di Microsoft Visual Basic, Applications Edition.

2. Clic inserire > Modulie incolla il codice seguente nel file Finestra del modulo.

Codice VBA: invia intervallo di celle come corpo da Excel

Sub EmailRange()
'Update 20131209
Dim WorkRng As Range
On Error Resume Next
xTitleId = "KutoolsforExcel"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
Application.ScreenUpdating = False
WorkRng.Select
ActiveWorkbook.EnvelopeVisible = True
With ActiveSheet.MailEnvelope
    .Introduction = "Please read this email."
    .Item.To = ""
    .Item.Subject = "information of kte"
    .Item.Send
End With
Application.ScreenUpdating = True
End Sub

Nota: Nel codice sopra, puoi modificare le seguenti informazioni in base alle tue necessità.

  • .Introduction = "Leggi questa email."
  • .Articolo.A = ""
  • .Item.Subject = "informazioni su kte"

3. Quindi fare clic F5 tasto per eseguire questo codice e verrà visualizzata una finestra di messaggio per ricordarti di selezionare un intervallo che desideri inviare.

doc-send-range1

4. Quindi fare clic su OKe verrà visualizzata una finestra di messaggio, al termine della barra di avanzamento, fare clic su Consentiree quindi l'intervallo specifico di celle è stato inviato al destinatario come corpo del messaggio.

doc-send-range2

Note:

1. Questi codici sono disponibili solo quando si utilizza Outlook come programma di posta.

2. Dopo aver inviato il foglio di lavoro corrente, puoi andare su Outlook per assicurarti che l'e-mail sia stata inviata correttamente.


Articoli correlati:

Come inviare un foglio di lavoro solo tramite Outlook da Excel?

Come inviare la cartella di lavoro corrente tramite Outlook da 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 (27)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Hi,
Thank you for sharing the code.
How can I re-size the object to make it smaller on the email body?

Thank you so much
This comment was minimized by the moderator on the site
Hi,

I've done everything as above and the result is: all works perfectly apart of the button :) Don't really care about this at the moment :)

Huge thank you!!! topic closed :)
This comment was minimized by the moderator on the site
Thank you for this! I will test it soon as I'll back from holiday. Have one more question. Have an issue with running vba codes by using Activex button (no action at all) even if code works perfectly on edit mode or when run by ctrl+selected button from keyboard. I'm just starting vba journey and have no
idea what I'm doing wrong :/
This comment was minimized by the moderator on the site
Hello, pawerl
You just need to copy and paste the code into the Microsoft Visual Basic for Applications window, and then click the Run button from the tool bar as below screenshot shown: (Note: in the code, S1 is the cell contains the email address that you want to send the email to. Please change them to your need.)

https://www.extendoffice.com/images/stories/comments/comment-skyyang/doc-send-emails.png

Please try again!
This comment was minimized by the moderator on the site
Hej,

Mam plik z 6 arkuszami. Każdy z arkuszy 2-6 musi zostać wysłany do innej grupy odbiorców jako załącznik excela. Czy da się to podpiąć pod 5 przycisków?
This comment was minimized by the moderator on the site
Hello, pawerl
To solve your problem, the below article may help you, please check it:

https://www.extendoffice.com/documents/excel/7178-send-each-sheet-to-different-email.html

Thank you!
This comment was minimized by the moderator on the site
Can we fixed ranges ? in macro its self
This comment was minimized by the moderator on the site
Hello everyone
I have a project to select range in sheet 1 to be sent by email one by one to many emails addresses written in sheet 2 in column A and if column B is empty with a certain subject and after sending he write in sheet 2 column b sent
And to wait time 10 seconds to send the next email as the condition of the server
Any one help me please ?   
This comment was minimized by the moderator on the site
Hi, hriad, " if column B is empty with a certain subject and after sending he write in sheet 2 column b sent
And to wait time 10 seconds to send the next email as the condition of the server" I don't understand this. Please retell me about your requirement.
This comment was minimized by the moderator on the site
Hello Sunny
first of all , thanks for your help , as the server put a condition to not send many emails in the same second , I want to wait 10 seconds after sending first email and the following one.
This comment was minimized by the moderator on the site
Hi, hriad, please try below code, after runing it, it will pop out a dialog for selecting a range which you want to send, then it send to addresses in sheet 2 column A and with the subjects in column B. Every 10 seconds, send to one address. You can change the code "Please read this email" as you need.
<div data-tag="code">Sub SendEmailRange()

'UpdateByExtendoffice20220414

Dim WorkRng As Range

Dim xSU, EV As Boolean

Dim xWSh As Worksheet

Dim xCount As Integer

Dim xI As Integer

On Error Resume Next

xTitleId = "KutoolsforExcel"

'select a range that used to send as body

Set WorkRng = Application.InputBox("Range", xTitleId, Application.Selection.Address, , , , , 8)

If WorkRng Is Nothing Then Exit Sub
WorkRng.Activate
WorkRng.Select

Set xWSh = ActiveWorkbook.Worksheets("Sheet2") 'the sheet that contains addresses and subjects

xCount = xWSh.UsedRange.Rows.Count

xSU = Application.ScreenUpdating

EV = ActiveWorkbook.EnvelopeVisible

Application.ScreenUpdating = False


For xI = 1 To xCount

If (xWSh.Range("A" & xI) = "") Then
Exit For
End If
ActiveWorkbook.EnvelopeVisible = True
With ActiveSheet.MailEnvelope
.Introduction = "Please read this email."

.Item.To = xWSh.Range("A" & xI)

.Item.Subject = xWSh.Range("B" & xI)

.Item.Send
End With
If (xI = xCount) Then

Exit For

End If

Application.Wait Now + TimeValue("0:00:10")

Next


Application.ScreenUpdating = xSU

ActiveWorkbook.EnvelopeVisible = EV

End Sub

This comment was minimized by the moderator on the site
Hello Sunny
Many many Thanks for your effort.... Thanks a lot
This comment was minimized by the moderator on the site
Hello everyone
I have a project to select range in sheet 1 to be sent by email one by one to many emails addresses written in sheet 2 in column A and if column B is empty with a certain subject and after sending he write in sheet 2 column b sent
And to wait time 10 seconds to send the next email as the condition of the server
Any one help me please ?   
This comment was minimized by the moderator on the site
Hi I have a table set up that I want staff to fill in and then a command button that will then automatically generate an email, however I want the data from the table to be in the email body. Is there a code for that? 
Thank you 
This comment was minimized by the moderator on the site
ich möchte das kopierte nicht als Datei in eine E-Mail einfügen, sondern per copy and paste in die E-Mail einfügen. Wie geht das in dem VBA-Code?
This comment was minimized by the moderator on the site
could we put as many email addresses to send to?
This comment was minimized by the moderator on the site
Hi, Carey, all above the VBAs can add many emails address (To, BCC, CC) to send to by using ; as separator. For instance,  .To = "; ; "
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