Copy data and send in outlook email

palibrar

New Member
Joined
May 24, 2014
Messages
13
Hi,

Could you please help m with a VBA code to cop data from excel and send in an email.

Thanks
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Hello

Add to the ThisWorkBook section;

Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)If MsgBox("Çalışma kitabı ekli olarak belirttiğiniz adrese gönderilsin mi?", vbQuestion + vbYesNo, "MAİL") = vbYes Then
    If Saved = False Then Saved = True
Dim OutApp As Object
    Dim OutMail As Object
    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)
    On Error Resume Next
    With OutMail
        .To = "[B][COLOR=#ff0000]xxx@xmail.com[/COLOR][/B]" 'Posta gönderilecek adres
        .CC = "" '(Carbon Copy) Bu şekilde eklediğiniz kişilere mailin bir kopyası gider.
        .BCC = "" '(Blind Carbon Copy). Bu şekilde eklediğiniz kişilere de mail gider ancak Gönderilen ve CC kısmına yazdığınız kişilerin bundan haberi olmaz.
        .Subject = "Dosyalarınız Yedeklenmiştir." ' Konu (Title)
        .Body = "Dosyalarınız Yedeklenmiştir." 'Yazmak istedikleriniz. (Prompt)
        .Attachments.Add ActiveWorkbook.FullName 'Bu çalışma kitabını ek olarak gönder.
        '.Attachments.Remove (1) 'Ek göndermek istemezsen
        '.Attachments.Add ("C:\test.txt") şeklinde de dosya eklenebilir.
        .Send  'yada .Send veya Display kullanılır.
    End With
    On Error GoTo 0
    Set OutMail = Nothing
    Set OutApp = Nothing
End If
End Sub
 
Upvote 0
What does below mean-

("Çalışma kitabı ekli olarak belirttiğiniz adrese gönderilsin mi?", vbQuestion + vbYesNo, "MAİL") 'Posta gönderilecek adres
Bu şekilde eklediğiniz kişilere mailin bir kopyası gider.
Bu şekilde eklediğiniz kişilere de mail gider ancak Gönderilen ve CC kısmına yazdığınız kişilerin bundan haberi olmaz.
.Subject = "Dosyalarınız Yedeklenmiştir." ' Konu (Title)
.Body = "Dosyalarınız Yedeklenmiştir." 'Yazmak istedikleriniz. (Prompt)
çalışma kitabını ek olarak gönder.
'Ek göndermek istemezsen
şeklinde de dosya eklenebilir.
'yada .

Please advise.
 
Upvote 0
Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)If MsgBox("[COLOR=#00ff00]Do you want to sent e-mail this work book?[/COLOR]", vbQuestion + vbYesNo, "MAİL") = vbYes Then    If Saved = False Then Saved = TrueDim OutApp As Object    Dim OutMail As Object    Set OutApp = CreateObject("Outlook.Application")    Set OutMail = OutApp.CreateItem(0)    On Error Resume Next    With OutMail        .To = "[B][COLOR=#ff0000]xxx@xmail.com[/COLOR][/B]" '[COLOR=#00ff00]Define here to your or anyone E-mail address where do you want to send it.[/COLOR]        .CC = "" '(Carbon Copy) [COLOR=#00ff00]If you add e-mails like that, than will be gone a copy e-mail another peoples.[/COLOR]        .BCC = "" '(Blind Carbon Copy). 'Ghost e-mail address, if you are using outlook, u know allways this subjects..        .Subject = [COLOR=#00ff00]"files are backed up[/COLOR]" ' Konu (Title)        .Body = "[COLOR=#00FF00][FONT=Verdana]files are backed up[/FONT][/COLOR][FONT=Verdana]." [COLOR=#00ff00]'If you want anything your message with e-mail, you will write from here. That will be sent automatically alltimes[/COLOR]. (Prompt)[/FONT]
        .Attachments.Add ActiveWorkbook.FullName '[COLOR=#00ff00]Sent this workbook like a additional.[/COLOR]        '.Attachments.Remove (1) '[COLOR=#00ff00]If you dont like additional.[/COLOR]        '.Attachments.Add ("C:\test.txt") [COLOR=#00ff00]can be add a file like that.[/COLOR]        .Send  'or .Send or Display can be use.    End With    On Error GoTo 0    Set OutMail = Nothing    Set OutApp = NothingEnd IfEnd Sub
 
Upvote 0
Hi,
Thanks a lot.
This was very useful.
But I want a code where the data should be copied from excel to outlook body not as an attachment.
Also before the mail is sent I want to see the drafted mail.
Then a msg should appear where when I say ok only then mail should be sent.
Thanks,
 
Upvote 0
Hi,
Thanks a lot.
This was very useful.
But I want a code where the data should be copied from excel to outlook body not as an attachment.
Also before the mail is sent I want to see the drafted mail.
Then a msg should appear where when I say ok only then mail should be sent.
Thanks,
 
Upvote 0
Hi there,

Can anyone please help me with a code where the data should be copied from excel to outlook body not as an attachment.
Also before the mail is sent I want to see the drafted mail.
Then a msg should appear where when I say ok only then mail should be sent.
Thanks,
 
Upvote 0

Forum statistics

Threads
1,213,510
Messages
6,114,044
Members
448,543
Latest member
MartinLarkin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top