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 / Outlook / Programming Forms / March 2006

Tip: Looking for answers? Try searching our database.

sending rtf,doc,text as message body in outllook 2003 in vb.net

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Digit Solver - 27 Mar 2006 01:17 GMT
Hi,

I am trying to send a document using vb.net and outlook and words, The type
of file i would like to send are (rtf, doc, txt) as the message body in the
outlook message. Any one with experince in this area the help will be surely
appreciated.

I have added the code below i get some type of hresult type error when i run
this.

Public Sub SendDocMsg(ByVal subjectp As String, ByVal pEmail As String, _
   ByVal fileDirLocation As String)

       recipient = pEmail
       subject = subjectp

       Dim oLApp As Object
       Dim oItem As Object
       Dim oDoc As Object
       

       On Error GoTo errorHandler

       
       'Create a new mailitem
       ' oOutlook = New Outlook.Application
       oLApp = CreateObject("Outlook.Application")
       oItem = oLApp.CreateItem(0)
       oDoc = CreateObject("Word.Application")
       oDoc.Visible = True
       oDoc.Documents.Open(fileDirLocation)

       With oItem

           'Set the recipient for the new email
           .To = mRecipient

           'Set the recipient for a copy
           '.CC = "recipient2@mail.com"

           'Set the subject
           .Subject = mSubject

           'The content of the document is used as the body for the email
           .Body = oDoc.ActiveDocument.Content

           .Send()
       End With

       
errorHandler:
       MsgBox(Err.Number & " " & Err.Description)
       'Clean up
       oItem = Nothing
       oLApp = Nothing
       oDoc = Nothing

   End Sub ' SendMsg

Signature

Digit Solver™

Sue Mosher [MVP-Outlook] - 30 Mar 2006 15:24 GMT
Body takes only a plain text string, no formatting. For an HTML message, set HTMLBody to the fully tagged HTML content, e.g. from an .htm file. For RTF, see http://www.outlookcode.com/d/formatmsg.htm for various options.

Do you also have Word 2003 installed?

Signature

Sue Mosher, Outlook MVP
  Author of Configuring Microsoft Outlook 2003
    http://www.turtleflock.com/olconfig/index.htm
  and Microsoft Outlook Programming - Jumpstart for
    Administrators, Power Users, and Developers
    http://www.outlookcode.com/jumpstart.aspx
 

> Hi,
>
[quoted text clipped - 54 lines]
>
>    End Sub ' SendMsg
Digit Solver - 30 Mar 2006 18:03 GMT
Yes, i have words installed but when i used the oDoc.ActiveDocument.contents
i get a HRESULT error for some reason i don't know why.

Signature

Digit Solver™

> Body takes only a plain text string, no formatting. For an HTML message, set HTMLBody to the fully tagged HTML content, e.g. from an .htm file. For RTF, see http://www.outlookcode.com/d/formatmsg.htm for various options.
>
[quoted text clipped - 58 lines]
> >
> >    End Sub ' SendMsg
Sue Mosher [MVP-Outlook] - 31 Mar 2006 15:37 GMT
Here's a better way to create a message with the Word document contents as the message body:

   Dim env as Office.MsoEnvelope = oDoc.ActiveDocument.MailEnvelope
   Dim oItem as Outlook.MailItem
   oItem = CType(env.Item, Outlook.MailItem)
   With oItem
       'Set the recipient for the new email
       .To = mRecipient
   
       'Set the recipient for a copy
       .CC = "recipient2@mail.com"

       'Set the subject
       .Subject = mSubject

       ' next statement will trigger security prompt
       .Send()
   End With    

The message format will always be HTML automatically.
Signature

Sue Mosher, Outlook MVP
  Author of Configuring Microsoft Outlook 2003
    http://www.turtleflock.com/olconfig/index.htm
  and Microsoft Outlook Programming - Jumpstart for
    Administrators, Power Users, and Developers
    http://www.outlookcode.com/jumpstart.aspx
 

> Yes, i have words installed but when i used the oDoc.ActiveDocument.contents
> i get a HRESULT error for some reason i don't know why.
[quoted text clipped - 61 lines]
>> >
>> >    End Sub ' SendMsg
 
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.