Word 97 Macro to Create Outlook '03 Email With Text Format

J

John Ciccone

Perhaps this should be in the Outlook discussion group, but I use a Word 97
macro that creates an email with Outlook 2003.

That email uses the contents of the current Word document as the body of the
email.

Test formatting is lost in the process. Any way to maintain (bold,
underline, colour, etc.)?

Thank you.

PS: The macro is from http://word.mvps.org/FAQs/InterDev/SendMail.htm:

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 document 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
 
D

Doug Robbins - Word MVP

Try using

ActiveDocument.Range.FormattedText

instead of

ActiveDocument.Content

but as you have no control over how the recipient views their email (many
prudent users will view them as plain text), you cannot be sure how it will
be seen by the recipient. Better to send the document as an attachment, and
really better to send it as a .pdf file unless the recipient needs to be
able to edit it which is probably not the case as you are sending it as the
body of an email message.

--
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
 
J

John Ciccone

Thanks, Doug.

Unfortunately it doesn't work. Strange as may seem I've got reasons to send
email with formatted text in the body of the email.

Any way to do this with HTML tags? I could certainly add to the active
document, but I don't know how to save it... IOW I end up with an email with
"<b>Hello</b>" in it.
 
G

Graham Mayor

A similar issue came up recently for sending formatted e-mails with Outlook
2007 and in theory at least it may work for you as long as you add the
Outlook object library to your template. The macro creates an Outlook
message with the clipboard content as the body. If it works for you it would
be simple enough to add the code to copy the document content first. I did
find that the macro crashed Word is Outlook was not already open when run
onb my system. Others had more success. At least it may point a way forward,

Sub Send_Extract_As_EMail()
' send the document in an Outlook Email message
' 2007 Graham Mayor, Tony Jollans, Doug Robbins
' & Sue Mosher

Dim bStarted As Boolean
Dim oOutlookApp As Outlook.Application
Dim oItem As Outlook.MailItem
Dim objDoc As Word.Document
Dim strEMail As String

strEMail = "<PR_EMAIL_ADDRESS>"
'Let the user choose the contact from Outlook
'And assign the email address to a variable

strEMail = Application.GetAddress("", strEMail, _
False, 1, , , True, True)
If strEMail = "" Then
MsgBox "User cancelled or no address listed", , "Cancel"
End If

On Error Resume Next

'Get Outlook if it's running
Set oOutlookApp = GetObject(, "Outlook.Application")

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

'Create a new mailitem
Set oItem = oOutlookApp.CreateItem(olMailItem)
Set objDoc = oItem.GetInspector.WordEditor
With oItem
.To = strEMail
.Subject = InputBox("Subject?")
Selection.Copy
objDoc.Range.Paste
.Display
End With

'Clean up
Set oItem = Nothing
Set oOutlookApp = Nothing
End Sub


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
J

John Ciccone

Thank you, Graham. But I can't even get close. Word does crash. Stepping
through the macro the last thing I can do is:

strEMail = Application.GetAddress("", strEMail, _

I have Outlook open. I've added the Reference "Microsoft Outlook 11.0 Object
Library"

Think I'm missing something?
 
G

Graham Mayor

The full line is actually

strEMail = Application.GetAddress("", strEMail, False, 1, , , True, True)

which I had wrapped to avoid problems with the e-mail editor. If the
corrected line doesn't work it may be that Word 97 does not have all the
hooks necessary in the VBA implementation to allow this to work. I did say
that 'in theory' it should work - but it was an untested theory as I don't
have access to Word 97.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

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