views:

37

answers:

2

Is there a way to add an attachment to an email you're sending out without the attachment being on the filesystem? From reading over the DOM (http://msdn.microsoft.com/en-us/library/bb175153%28office.12%29.aspx) it says that the attachment source can be either a file path or "an Outlook item that constitutes the attachment". I don't use VBA of the office DOMs all that much and I'm not sure what this is. In addition, all the examples I can find are only giving usage examples by using the filesystem path.

I'm calling this from Word for documents that create themselves by filling out some form fields, then print themselves. I'd like them to go out via E-mail as well, but have no need for a permanent copy of the created file. I do realize that I could save them off to a temp directory, attach the saved file, then delete the file once the mail object is sent. It seems a waste to do this though.

Is there an way I can have Word pass the in-memory Document object off to Outlook to attach to the email?

A: 

Oesor,

I made an assumption that email should get sent automatically, so SendMail method is out. I tried a couple of things to see whether it would work. In both cases code would be embedded in your Word file. In pre-2007 Word you could use RoutingSlip functionality:

 ActiveDocument.HasRoutingSlip = True   'Creates RoutingSlip
 With ActiveDocument.RoutingSlip
   .Subject = "email Subject"
   .AddRecipient = "[email protected]"
   .Delivery = wdAllAtOnce
 End With
 ActiveDocument.Route

Apparently, this code doesn't work in Word 2007. So instead you can use SendForReview functionality:

ActiveDocument.SendForReview "[email protected]", "email subject", False, True

Email gets sent right away (w/o the popup Outlook window), but a couple of caveats exist: the document has to have a corresponding file - it won't work for a new document that has never been saved, and the first time the recipient opens the attached document from e-mail there may be a popup message about starting the review process.

I hope this helps,

Max.

Meringros
Actually, I really don't care about the popup that .MailSend generates. However, your caveat has exactly what I'm looking to not do -- generate a file by filling in some fields, then need to save it to disk before attaching it as a document.I also need to specify the contents of the mail and simply attach the document, so I guess I'll live by saving it to temp, attaching it, then deleting it when done. Thanks!
Oesor
A: 

The answer is no, you cannot attach an in-memory document to an outlook mailitem without saving it to disk first.

Oesor