Email question

J

jim

I would like to duplicate the functionality of the email "Send a copy"
button through VBA. What I want to do is send out properly formatted
letters via email but not the actual .doc files. I want the user to
be able to select an email address contained in the body of the
letter, run my macro and let the code take care of emailing the
letter, rather than click the email button on the toolbar, enter the
email address and click the "send a copy" button..

I tried the code from the Word MVP site that was contributed by Astrid
Zeelenberg entitled" How to send an email from Word using VBA" but
creating an Outlook MailItem will not allow the letter to retain its
particular formatting. It sends the letter as an email but it strips
out any and all formatting. I want to retain the format of the
letter.

Can I do this with VBA in word?

Because somebody is going to ask to see it, this is the code that will
send the document contents as a plaintext email without any
formatting.

Sub SendDocumentInMail()

Dim bStarted As Boolean
Dim oOutlookApp As Outlook.Application
Dim oItem As Outlook.MailItem

On Error Resume Next

'Get Outlook if it's running
Set oOutlookApp = GetObject(, "Outlook.Application")
If Err <> 0 Then
'Outlook wasn't running, start it from code
Set oOutlookApp = CreateObject("Outlook.Application")
bStarted = True
End If

'Create a new mailitem
Set oItem = oOutlookApp.CreateItem(olMailItem)

With oItem
'Set the recipient for the new email
.To = "(e-mail address removed)"
'Set the recipient for a copy
.CC = "(e-mail address removed)"
'Set the subject
.Subject = "New subject"
'The content of the doc is used as the body for the email
.Body = ActiveDocument.Content
.Send
End With

If bStarted Then
'If we started Outlook from code, then close it
oOutlookApp.Quit
End If

'Clean up
Set oItem = Nothing
Set oOutlookApp = Nothing

End Sub

Does anybody have any ideas?

jim
 
D

Doug Robbins - Word MVP

Use:

With oItem
'Set the recipient for the new email
.To = "(e-mail address removed)"
'Set the recipient for a copy
.CC = "(e-mail address removed)"
'Set the subject
.Subject = "New subject"
.BodyFormat = olFormatHTML
.Display
Set objDoc = .GetInspector.WordEditor
Set objSel = objDoc.Windows(1).Selection
objSel.Paste
.Send
End With



--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 

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