ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Sending mail (https://www.excelbanter.com/excel-programming/421085-sending-mail.html)

Tomas Stroem

Sending mail
 
I want to send a file to multiple persons by using a macro that runs each
time the file is saved. It works perfectly well with one person, but not when
I try to add more names. What is the correct syntax to do this? Code added
below

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
ActiveWorkbook.SendMail ,
", Subject:="Filename"

End Sub

--
Tomas S

Franz E

Sending mail
 
Online help says:
- for one recipient you need to use text, exactly as you do
- for more than one recipient you need to use a matrix with text strings.


"Tomas Stroem" wrote:

I want to send a file to multiple persons by using a macro that runs each
time the file is saved. It works perfectly well with one person, but not when
I try to add more names. What is the correct syntax to do this? Code added
below

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
ActiveWorkbook.SendMail ,
", Subject:="Filename"

End Sub

--
Tomas S


Joshua Fandango

Sending mail
 
Hi Tomas,

The following works great for me.
Have it in a standard module & call it from the Before Save event.

Sub Email_This_Wbk()
Dim OutApp As Object
Dim OutMail As Object

Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
Set OutMail = OutApp.CreateItem(0)

On Error Resume Next
With OutMail
.To = "
.CC = "
.BCC = "
.Subject = "This week's reports"
.Body = "What ever you want"
.Attachments.Add ActiveWorkbook.FullName
.display
End With
On Error GoTo 0

Set OutMail = Nothing
Set OutApp = Nothing
End Sub
----------------------------------------------------------------

HtH,
JF



On 10 Dec, 07:26, Tomas Stroem
wrote:
I want to send a file to multiple persons by using a macro that runs each
time the file is saved. It works perfectly well with one person, but not when
I try to add more names. What is the correct syntax to do this? Code added
below

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
ActiveWorkbook.SendMail ,
", Subject:="Filename"

End Sub

--
Tomas S



Tomas Stroem

Sending mail
 
Joshua,

This works great for me to, Many thanks !!
--
Tomas S


"Joshua Fandango" wrote:

Hi Tomas,

The following works great for me.
Have it in a standard module & call it from the Before Save event.

Sub Email_This_Wbk()
Dim OutApp As Object
Dim OutMail As Object

Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
Set OutMail = OutApp.CreateItem(0)

On Error Resume Next
With OutMail
.To = "
.CC = "
.BCC = "
.Subject = "This week's reports"
.Body = "What ever you want"
.Attachments.Add ActiveWorkbook.FullName
.display
End With
On Error GoTo 0

Set OutMail = Nothing
Set OutApp = Nothing
End Sub
----------------------------------------------------------------

HtH,
JF



On 10 Dec, 07:26, Tomas Stroem
wrote:
I want to send a file to multiple persons by using a macro that runs each
time the file is saved. It works perfectly well with one person, but not when
I try to add more names. What is the correct syntax to do this? Code added
below

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
ActiveWorkbook.SendMail ,
", Subject:="Filename"

End Sub

--
Tomas S




Joshua Fandango

Sending mail
 
Just noticed... in the With OutMail change ".display" to ".send" to
have it actually send

Ooops! :)

On 10 Dec, 12:16, Tomas Stroem
wrote:
Joshua,

This works great for me to, Many thanks !!
--
Tomas S



"Joshua Fandango" wrote:
Hi Tomas,


The following works great for me.
Have it in a standard module & call it from the Before Save event.


Sub Email_This_Wbk()
Dim OutApp As Object
Dim OutMail As Object


* Set OutApp = CreateObject("Outlook.Application")
* OutApp.Session.Logon
* Set OutMail = OutApp.CreateItem(0)


* On Error Resume Next
* With OutMail
* * .To = "
* * .CC = "
* * .BCC = "
* * .Subject = "This week's reports"
* * .Body = "What ever you want"
* * .Attachments.Add ActiveWorkbook.FullName
* * .display
* End With
* On Error GoTo 0


* Set OutMail = Nothing
* Set OutApp = Nothing
End Sub
----------------------------------------------------------------


HtH,
JF


On 10 Dec, 07:26, Tomas Stroem
wrote:
I want to send a file to multiple persons by using a macro that runs each
time the file is saved. It works perfectly well with one person, but not when
I try to add more names. What is the correct syntax to do this? Code added
below


Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
ActiveWorkbook.SendMail ,
", Subject:="Filename"


End Sub


--
Tomas S- Hide quoted text -


- Show quoted text -



Tomas Stroem

Sending mail
 
Will change this to make it exactly as I want to have it run.

Again Many Thanks
--
Tomas S


"Joshua Fandango" wrote:

Just noticed... in the With OutMail change ".display" to ".send" to
have it actually send

Ooops! :)

On 10 Dec, 12:16, Tomas Stroem
wrote:
Joshua,

This works great for me to, Many thanks !!
--
Tomas S



"Joshua Fandango" wrote:
Hi Tomas,


The following works great for me.
Have it in a standard module & call it from the Before Save event.


Sub Email_This_Wbk()
Dim OutApp As Object
Dim OutMail As Object


Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
Set OutMail = OutApp.CreateItem(0)


On Error Resume Next
With OutMail
.To = "
.CC = "
.BCC = "
.Subject = "This week's reports"
.Body = "What ever you want"
.Attachments.Add ActiveWorkbook.FullName
.display
End With
On Error GoTo 0


Set OutMail = Nothing
Set OutApp = Nothing
End Sub
----------------------------------------------------------------


HtH,
JF


On 10 Dec, 07:26, Tomas Stroem
wrote:
I want to send a file to multiple persons by using a macro that runs each
time the file is saved. It works perfectly well with one person, but not when
I try to add more names. What is the correct syntax to do this? Code added
below


Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
ActiveWorkbook.SendMail ,
", Subject:="Filename"


End Sub


--
Tomas S- Hide quoted text -


- Show quoted text -





All times are GMT +1. The time now is 10:11 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com