• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 725
  • Last Modified:

Edit Word Macro to send email in Rich Text

With the help of a couple of Expert Exchange experts, I have put together a MS Word 2007 document that uses a macro to copy and paste a couple of pages of the document and insert them into an Outlook email message.  It also inserts the email address and the subject line.  I thought I was done but then when I tested it I found that the check boxes that are part of the Word document were not arriving when the email was sent.  However I found that if I switched the email format to Rich Text instead of HTML, the check boxes would arrive correctly.

Can anyone help me edit this macro to include a line that will automatically switch the email to Rich Text format?

Thank you.
Sub SendDocAsMail()

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

On Error Resume Next

'Start Outlook if it isn't running
Set oOutlookApp = GetObject(, "Outlook.Application")
If Err <> 0 Then
    Set oOutlookApp = CreateObject("Outlook.Application")
End If

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

oItem.Subject = "New or Transferred User"
oItem.Recipients.Add "email address@generic.com"
'oItem.Recipients.Add "AnotherAddressIfYouWant.domain.com"

'Allow the user to write a short intro and put it at the top of the body
'Dim msgIntro As String
'msgIntro = InputBox("Write a short intro to put above your default " & _
            "signature and current document." & vbCrLf & vbCrLf & _
            "Press Cancel to create the mail without intro and " & _
            "signature.", "Intro")

'Copies pages 2 -4
ThisDocument.Unprotect Password:=""
Dim rgePages As Range
Selection.GoTo What:=wdGoToPage, Which:=wdGoToAbsolute, Count:=2
Set rgePages = Selection.Range
Selection.GoTo What:=wdGoToPage, Which:=wdGoToAbsolute, Count:=4
rgePages.End = Selection.Bookmarks("\Page").Range.End
rgePages.Select
rgePages.Copy
ThisDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=""

'Set the WordEditor
Dim objInsp As Outlook.Inspector
Dim wdEditor As Word.Document
Set objInsp = oItem.GetInspector
Set wdEditor = objInsp.WordEditor

'Write the intro if specified
Dim i As Integer
If msgIntro = IsNothing Then
    i = 1
    'Comment the next line to leave your default signature below the document
    wdEditor.Content.Delete
Else
    'Write the intro above the signature
    wdEditor.Characters(1).InsertBefore (msgIntro)
    i = wdEditor.Characters.Count
    wdEditor.Characters(i).InlineShapes.AddHorizontalLineStandard
    wdEditor.Characters(i + 1).InsertParagraph
    i = i + 2
End If

'Place the current document under the intro and signature
wdEditor.Characters(i).PasteAndFormat (wdFormatOriginalFormatting)

'Display the message
oItem.Display

'Clean up
Set oItem = Nothing
Set oOutlookApp = Nothing
Set objInsp = Nothing
Set wdEditor = Nothing

End Sub

Open in new window

0
HLR6S
Asked:
HLR6S
  • 2
  • 2
1 Solution
 
Chris BottomleyCommented:
Try the line:

oitem.bodyformat = olformatrichtext

Added it already below.

Chris
Sub SendDocAsMail()

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

On Error Resume Next

'Start Outlook if it isn't running
Set oOutlookApp = GetObject(, "Outlook.Application")
If Err <> 0 Then
    Set oOutlookApp = CreateObject("Outlook.Application")
End If

'Create a new message
Set oItem = oOutlookApp.CreateItem(olMailItem)
oitem.bodyformat = olformatrichtext
oItem.Subject = "New or Transferred User"
oItem.Recipients.Add "email address@generic.com"
'oItem.Recipients.Add "AnotherAddressIfYouWant.domain.com"

'Allow the user to write a short intro and put it at the top of the body
'Dim msgIntro As String
'msgIntro = InputBox("Write a short intro to put above your default " & _
            "signature and current document." & vbCrLf & vbCrLf & _
            "Press Cancel to create the mail without intro and " & _
            "signature.", "Intro")

'Copies pages 2 -4
ThisDocument.Unprotect Password:=""
Dim rgePages As Range
Selection.GoTo What:=wdGoToPage, Which:=wdGoToAbsolute, Count:=2
Set rgePages = Selection.Range
Selection.GoTo What:=wdGoToPage, Which:=wdGoToAbsolute, Count:=4
rgePages.End = Selection.Bookmarks("\Page").Range.End
rgePages.Select
rgePages.Copy
ThisDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=""

'Set the WordEditor
Dim objInsp As Outlook.Inspector
Dim wdEditor As Word.Document
Set objInsp = oItem.GetInspector
Set wdEditor = objInsp.WordEditor

'Write the intro if specified
Dim i As Integer
If msgIntro = IsNothing Then
    i = 1
    'Comment the next line to leave your default signature below the document
    wdEditor.Content.Delete
Else
    'Write the intro above the signature
    wdEditor.Characters(1).InsertBefore (msgIntro)
    i = wdEditor.Characters.Count
    wdEditor.Characters(i).InlineShapes.AddHorizontalLineStandard
    wdEditor.Characters(i + 1).InsertParagraph
    i = i + 2
End If

'Place the current document under the intro and signature
wdEditor.Characters(i).PasteAndFormat (wdFormatOriginalFormatting)

'Display the message
oItem.Display

'Clean up
Set oItem = Nothing
Set oOutlookApp = Nothing
Set objInsp = Nothing
Set wdEditor = Nothing

End Sub

Open in new window

0
 
HLR6SAuthor Commented:
That worked perfectly.  Thank you!
0
 
HLR6SAuthor Commented:
This worked perfectly.
0
 
Chris BottomleyCommented:
You're welcome ... glad to help.

Chris
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now