Sending Mail using VBA

C

craigoutinoz

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 = "(e-mail address removed)"
.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
 
N

Norman Jones

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top