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 / December 2007

Tip: Looking for answers? Try searching our database.

How to capture programatically emailing a Word 2003 doc?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
James - 06 Dec 2007 22:06 GMT
I am running Word 2003 (Outlook 2003 for those interested) and I need
to programatically save a document to HTML-filtered format then use
the File>Send To>Mail Recipient to send it off, also programatically.
Can anyone give me a start on this, particularely on the mail portion?

TIA
Tony Jollans - 07 Dec 2007 07:34 GMT
The easy  bit:

   ActiveDocument.SaveAs FileName:=whatever, _
                                          FileFormat:=wdFormatFilteredHTML

AFAIK, you cannot completely automate the sending of e-mail through Word but
you can do it with Outlook. I posted this for someone else  the other day
and noted that, if Outlook wasn't already running, the Inspector was needed

   Dim appOL 'As Outlook.Application
   Dim E_Mail 'As Outlook.MailItem
   Dim Needed 'As Outlook.Inspector

   Set appOL = CreateObject("Outlook.Application")
   Set E_Mail = appOL.CreateItem(0) 'olMailItem)
   Set Needed = E_Mail.GetInspector
   E_Mail.Recipients.Add "User@Example.com"
   E_Mail.Subject = "Something meaningful"
   E_Mail.Attachments.Add whatever_you_saved_it_as
   E_Mail.Send

   Set Needed = Nothing
   Set E_Mail = Nothing
   Set appOL = Nothing

You will get messages from the Object Model Guard about another application
trying to send e-mail; if this turns out to be a problem, investigate
ClickYes (just google for it).

Signature

Enjoy,
Tony

>I am running Word 2003 (Outlook 2003 for those interested) and I need
> to programatically save a document to HTML-filtered format then use
> the File>Send To>Mail Recipient to send it off, also programatically.
> Can anyone give me a start on this, particularely on the mail portion?
>
> TIA
James - 07 Dec 2007 13:19 GMT
On 7 Dec, 02:34, "Tony Jollans" <My forename at my surname dot com>
wrote:
> The easy  bit:
>
[quoted text clipped - 37 lines]
>
> - Show quoted text -

This would send as attachment, no? I need it in the body of the
message.
Tony Jollans - 08 Dec 2007 01:51 GMT
I don't really know how to do this and there may well be a better way but,
hopefully, this will put you on the right track.

After saving the file as HTML, close it, read it as text and apply it to the
e-mail's HTMLBody property. You may  have to make sure Outlook is set up
with HTML format as default - and I don't know how to do that
programmatically. Anyway here's some amended code that may work - let me
know.

   FileName = "C:\whatever.htm"

   ActiveDocument.SaveAs FileName, wdFormatHTML
   ActiveDocument.Close

   Set fso = CreateObject("Scripting.FileSystemObject")
   Set objHTML = fso.GetFile(FileName).OpenAsTextStream(1, -2)
   strHTML = objHTML.ReadAll
   objHTML.Close
   Set objHTML = Nothing
   Set fso = Nothing

   Dim appOL 'As Outlook.Application
   Dim E_Mail 'As Outlook.MailItem
   Dim Needed 'As Outlook.Inspector

   Set appOL = CreateObject("Outlook.Application")
   Set E_Mail = appOL.CreateItem(0) 'olMailItem)
   Set Needed = E_Mail.GetInspector
   E_Mail.Recipients.Add "User@Example.com"
   E_Mail.Subject = "Something meaningful"
   'E_Mail.Attachments.Add whatever_you_saved_it_as
   E_Mail.HTMLBody = strHTML
   E_Mail.Send

   Set Needed = Nothing
   Set E_Mail = Nothing
   Set appOL = Nothing

Signature

Enjoy,
Tony

> On 7 Dec, 02:34, "Tony Jollans" <My forename at my surname dot com>
> wrote:
[quoted text clipped - 46 lines]
> This would send as attachment, no? I need it in the body of the
> message.
 
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.