ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Sending Mail using VBA (https://www.excelbanter.com/excel-programming/366066-sending-mail-using-vba.html)

[email protected]

Sending Mail using VBA
 
Hi All,

I have the below coding however it keeps returning a bug. I am adding
it to the tail end of an error trapping function. However I can't get
it working on it's own never mind at the end of the original coding.
The rest works fine, just not this bit. I want to send a newly saved
copy to a specific address, including ranges in the new saved name,
however I can't includ the date nor will it send.??

Can anyone help?

Thanks

Craig



Public Function Open_mail()


Application.ScreenUpdating = False
ActiveSheet.Copy
Set wb = ActiveWorkbook

With wb
.SaveAs ThisWorkbook.Name _
& " " & strdate & Range("B13").Value & Range("B14").Value
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(olMailItem)
With OutMail
.To = "
.CC = ""
.BCC = ""
.Subject = "Credit Card Form" & Range("B13").Value &
Range("B14").Value
.Body = "This is a test... help!"
.Attachments.Add wb.FullName
'You can add other files also like this
'.Attachments.Add ("C:\test.txt")
'.Display
.Send 'or use .Display
End With
.ChangeFileAccess xlReadOnly
Kill .FullName
.Close False
End With
Application.ScreenUpdating = True
Set OutMail = Nothing
Set OutApp = Nothing
End Function


Norman Jones

Sending Mail using VBA
 
Hi Craig,

Your code (or Ron de Bruin's code!) worked for me, as is.

I merely changed to mail adress and explicitly dimmed the variables - but
these steps should not affect the functionality of the code.

Perhaps your (undisclosed) error pertains to the calling code?


---
Regards,
Norman



wrote in message
ups.com...
Hi All,

I have the below coding however it keeps returning a bug. I am adding
it to the tail end of an error trapping function. However I can't get
it working on it's own never mind at the end of the original coding.
The rest works fine, just not this bit. I want to send a newly saved
copy to a specific address, including ranges in the new saved name,
however I can't includ the date nor will it send.??

Can anyone help?

Thanks

Craig



Public Function Open_mail()


Application.ScreenUpdating = False
ActiveSheet.Copy
Set wb = ActiveWorkbook

With wb
.SaveAs ThisWorkbook.Name _
& " " & strdate & Range("B13").Value & Range("B14").Value
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(olMailItem)
With OutMail
.To = "
.CC = ""
.BCC = ""
.Subject = "Credit Card Form" & Range("B13").Value &
Range("B14").Value
.Body = "This is a test... help!"
.Attachments.Add wb.FullName
'You can add other files also like this
'.Attachments.Add ("C:\test.txt")
'.Display
.Send 'or use .Display
End With
.ChangeFileAccess xlReadOnly
Kill .FullName
.Close False
End With
Application.ScreenUpdating = True
Set OutMail = Nothing
Set OutApp = Nothing
End Function





All times are GMT +1. The time now is 01:40 PM.

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