Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / May 2008

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
John Ciccone - 05 May 2008 18:18 GMT
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 = "recipient@mail.com"
   'Set the recipient for a copy
   .CC = "recipient2@mail.com"
   '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
Doug Robbins - Word MVP - 05 May 2008 20:43 GMT
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.

Signature

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

> Perhaps this should be in the Outlook discussion group, but I use a Word
> 97
[quoted text clipped - 52 lines]
>
> End Sub
John Ciccone - 05 May 2008 22:01 GMT
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.

> Try using
>
[quoted text clipped - 67 lines]
> >
> > End Sub
Graham Mayor - 06 May 2008 07:58 GMT
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

Signature

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

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

> Thanks, Doug.
>
[quoted text clipped - 86 lines]
>>>
>>> End Sub
John Ciccone - 10 May 2008 22:59 GMT
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?

> 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
[quoted text clipped - 142 lines]
> >>>
> >>> End Sub
Graham Mayor - 11 May 2008 06:04 GMT
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.

Signature

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

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

> Thank you, Graham. But I can't even get close. Word does crash.
> Stepping through the macro the last thing I can do is:
[quoted text clipped - 161 lines]
>>>>>
>>>>> End Sub
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.