[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

adding attachement to mail envelope

Posted on 2009-02-23
9
Medium Priority
?
480 Views
Last Modified: 2012-05-06
I am trying to add an attachment to a document using the mail envelope object, as in the code below. It runs, but no attachment is produced. Ideas? Thanks
Dim itm As Object
Dim itmAttachment As Object
 
Set wbDest = Documents.Open(fileName:="H:\james\email macros\temp\" & fileName & ".rtf", ConfirmConversions:=False, _
        ReadOnly:=False, AddToRecentFiles:=False, PasswordDocument:="", _
        PasswordTemplate:="", Revert:=False, WritePasswordDocument:="", _
        WritePasswordTemplate:="", Format:=wdOpenFormatAuto)
        
        wbDest.Windows(1).EnvelopeVisible = True
        Set itm = wbDest.MailEnvelope.Item
        itm.BodyFormat = olformatrichtext
        itm.To = "John"
        itm.SentOnBehalfOfName = "John"
        itm.Subject = industryName & " - " & title
        
        Set itmAttachment = itm.Attachments
        itmAttachment.Add "C:\test.doc"
        itm.Save

Open in new window

0
Comment
Question by:jwagman
  • 5
  • 4
9 Comments
 
LVL 19

Expert Comment

by:dlc110161
ID: 23734402
I got it to work using the following code...

Dawn Crosier-Bleuel
Word MVP
Sub MailTest()
Dim wbDest As Word.Document
Dim objEnv As Office.MsoEnvelope
Dim objMailItem As Outlook.MailItem
 
Set wbDest = Documents.Open(FileName:="C:\test.rtf", ConfirmConversions:=False, _
        ReadOnly:=False, AddToRecentFiles:=False, PasswordDocument:="", _
        PasswordTemplate:="", Revert:=False, WritePasswordDocument:="", _
        WritePasswordTemplate:="", Format:=wdOpenFormatAuto)
        
        wbDest.Windows(1).EnvelopeVisible = True
 
Set objEnv = ActiveDocument.MailEnvelope
Set objMailItem = objEnv.Item
    
    With objMailItem
        .To = "John"
        .Subject = "a test from Word"
        .SentOnBehalfOfName = "John"
        .Attachments.Add "C:\Test.doc"
    End With
 
End Sub

Open in new window

0
 

Author Comment

by:jwagman
ID: 23744017
However, as soon as I add a line making the body of the Outlook item rich text (see below), the attachment seems to disappear?
Dim objEnv As Office.MsoEnvelope
Dim objMailItem As Outlook.MailItem
 
Set wbDest = Documents.Open(fileName:="C:\temp\" & fileName & ".rtf", ConfirmConversions:=False, _
        ReadOnly:=False, AddToRecentFiles:=False, PasswordDocument:="", _
        PasswordTemplate:="", Revert:=False, WritePasswordDocument:="", _
        WritePasswordTemplate:="", Format:=wdOpenFormatAuto)
        
        wbDest.Windows(1).EnvelopeVisible = True
 
Set objEnv = ActiveDocument.MailEnvelope
Set objMailItem = objEnv.Item
    
    With objMailItem
        .BodyFormat = olFormatRichText
        .To = "james.wagman@test.com"
        .Subject = "a test from Word"
'        .SentOnBehalfOfName = "John"
        .Attachments.Add "C:\test1.rtf"
    End With

Open in new window

0
 
LVL 19

Expert Comment

by:dlc110161
ID: 23745837
Why do you need to do that? The document opened is already rich text? You are using Word as your email editor basically since you are IN Word which has all the rich features available.

Dawn Crosier-Bleuel
Word MVP
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

Author Comment

by:jwagman
ID: 23745999
But unless I specify bodyformat as rtf the outlook message comes in as html (even if I change my outlook settings)...
0
 
LVL 19

Expert Comment

by:dlc110161
ID: 23746119
We force all of our mail to come in HTML so that the attachments show on the attachment line rather than embedded in the body of the document.. The BodyFormat as Rich Text and the Attachment on the Attachment line are mutually exclusive. Sorry.

Dawn Crosier-Bleuel
Word MVP
0
 

Author Comment

by:jwagman
ID: 23746151
But I can do it manually? Not programmatically? Why is that?
0
 
LVL 19

Accepted Solution

by:
dlc110161 earned 2000 total points
ID: 23746202
When you do it manually you are overriding the BodyFormat as Rich Text command.

For instance, if you run the code that converts your message to Rich Text. Then you add the attachment, then run the code to convert the message to Rich Text, the attachment is dropped.

Dawn Crosier-Bleuel
Word MVP
0
 

Author Comment

by:jwagman
ID: 23746401
Why can't Outlook send rich text and attachments? Just curious.
0
 

Author Comment

by:jwagman
ID: 23746455
I'd be happy to have it in the attachment in the body of the message - is that possible?
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Shortcuts in Word Just the other day I had a training for Microsoft and they wanted me to show how well the new Windows and Office behaved on a touch device, which by the way is great, but it was only then that I realized that using keyboard shortc…
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
This video teaches the viewer how to align pictures around text while keeping the text properly aligned in the document.
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.
Suggested Courses

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question