emailing document through Word OLE

T

texasHawkeye

I am trying to send an email using Word using OLE controls. I would like to
duplicate File -> Send To -> Mail Recipient. Macros have not been helpful as
I am not sure if Word is using an Outlook add-in to do the dirty work behind
the scenes.
Here is some of what I have tried so far...
1)
ole_doc = CREATE oleobject
ole_olk = CREATE oleobject
ole_msg = CREATE oleobject
ls_filename = "C:\test.htm"

ole_doc.ConnectToNewObject("word.application")
ole_doc.visible = true
ole_doc.Documents.Open(ls_filename)
ole_olk.ConnectToNewObject("Outlook.application")
ole_msg = ole_olk.createItem(0)
ole_msg.to = '(e-mail address removed)'
ole_msg.subject = 'Testing subj.'
ole_msg.BodyFormat = 2 //HTML
ole_msg.HTMLBody = ole_doc.ActiveDocument.Content
ole_msg.Display
ole_doc.Documents.Close()
ole_doc.Quit()

destroy ole_doc
destroy ole_olk
destroy ole_msg
- this always strips the email of formatting, hyperlinks, and images even
though it's an HTML format

2)
ole_doc = CREATE oleobject
ls_filename = "C:\test.htm"

ole_doc.ConnectToNewObject("word.application")
ole_doc.visible = true
ole_doc.Documents.Open(ls_filename)
ole_doc.ActiveDocument.HasRoutingSlip = True
ole_doc.ActiveDocument.RoutingSlip.Subject = 'Test Subject'
ole_doc.ActiveDocument.RoutingSlip.AddRecipient('(e-mail address removed)')
ole_doc.ActiveDocument.RoutingSlip.Delivery = 0
ole_doc.ActiveDocument.RoutingSlip.ReturnWhenDone = false
ole_doc.Options.SendMailAttach = false
ole_doc.ActiveDocument.Route
ole_doc.Documents.Close()
ole_doc.Quit()
destroy ole_doc

- this sends the email with the document as an attachment. I've tried
"ole_doc.Options.SendMailAttach = false" as well without success.

I am writing this for a PowerBuilder 10 application but would take anything
I can get at this point...

Thanks
 
D

Doug Robbins

See the article "How to send an email from Word using VBA" at:

http://word.mvps.org/FAQs/InterDev/SendMail.htm


--
Please respond to the Newsgroup for the benefit of others who may be
interested. Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP
 
T

texasHawkeye

This is soooo close to what I need. I must keep the formatting and the
document can not be an attachment. Since It can't be an attachment, I can't
use the Routing Slip. And since I need the formatting, I can't use the
message.Body = ActiveDocument.Content. Is this not possible?

What about setting Word's ActiveWindow.EnvelopeVisible = True. How do I set
the .To and .Subject line this way (and never even have to open or mess with
Outlook). The ActiveWindow.EnvelopeVisible = True come from a macro when I
do a File -> Send To -> Mail Recipient.
 
T

texasHawkeye

I have tried a new direction adapted from the document listed in Doug Robbins
reply. Instead of inserting the ActiveDocuemnt.Content of a .doc into the
ole_message.Body, I...
1) saved the .doc as a .htm
2) saved that .htm as a .txt
3) inserted the ActiveDocuemnt.Content of the .txt into the
message.HTMLBody. this converts the .html text back into a readable format.
The drawback is that my images are lost in the process. I will have to
research a way to embedd these images as I haven't figured that out yet.
Thanks for the help and I hope that this solution will help someone else too!
 
Top