jwagman
asked on
Using VBA - send email from Word
I'd like to construct some VBA which will automate the sending of a word document via email from within word. I can do it by hand simply by creating the document (btw, I'm saving the doc as filtered HTML, and it has tables in it) and doing File>Send To>Mail Recipient. I try to "record" this as a macro, but it won't let me record the mailing portion of it. Can I do it programatically? I did try the sendmail method, but it didn't preserve any ot the formatting, tables, etc. TIA.
ASKER
Hi,
I need to send the doc in the body of the message, not as attachment. I've tried a few different ways but usually the tables, etc. from the doc don't come through in the email.
Any ideas?
I need to send the doc in the body of the message, not as attachment. I've tried a few different ways but usually the tables, etc. from the doc don't come through in the email.
Any ideas?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
This works for me...
Dim OutApp As Object
Dim OutMail As Object
Set OutApp = CreateObject("Outlook.Appl ication")
OutApp.Session.Logon
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.To = "email@email.com"
.CC = ""
.BCC = ""
.Subject = "Weekly Ticket Update"
.HtmlBody = "<html><b>Hi there</b></html>"
'.Attachments.Add ActiveWorkbook.FullName
'You can add other files also like this
'.Attachments.Add ("c:\")
.Send 'or use .Display
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
Dim OutApp As Object
Dim OutMail As Object
Set OutApp = CreateObject("Outlook.Appl
OutApp.Session.Logon
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.To = "email@email.com"
.CC = ""
.BCC = ""
.Subject = "Weekly Ticket Update"
.HtmlBody = "<html><b>Hi there</b></html>"
'.Attachments.Add ActiveWorkbook.FullName
'You can add other files also like this
'.Attachments.Add ("c:\")
.Send 'or use .Display
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
What is the vb macro in word if you want to send the active/open Word doc via email with an e-mail macro ?
The attached code should get you a decent start.
Regards,
Patrick
Open in new window