PDA

View Full Version : Attaching current document as Email attachment in Word 2007



Robtyketto
12-08-2007, 11:26 AM
Greetings,

I've spent the last few hours trying to find a method from within Word 2007 (using VBA) to send emails using Outlook express as the default mailer.

Firstly I recorded the macro of sending file as email.
Which hi-lighted .Sendmail , unfortunately it appears it has NO paramaters so cannot specify subject or email reciptents.

Then I looked at the WordMVP site which detailed a rather snazzy and simple method.
Which I then find out has been REMOVED in word 2007, you cannot use routing slip method.

The other methods on the page appear not to work either due to me wanting to use Outlook express.

Can some assist me in sending emails from within word 2007 document?

Forgot to mention I have post this in the microsoft..publicword.vba newsgroups !!

Thanks
Stressed Rob :banghead:

Robtyketto
12-08-2007, 12:00 PM
I now have outlook 2007 setup and running.

I've added this code :-

Sub SendWithEnvelope()
Dim OutMail As Object
Dim OutApp As Object
Set OutApp = CreateObject("Word.Application")
Set OutMail = ActiveDocument.MailEnvelope
With OutMail
.To = "testemail@aol.com"
.Send
End With
End Sub

When running error 'Run-time error 430'
"Class does not support automation or does not support expected interface"

Any ideas?

MailEnvelope is selectable with .Activedocument.

Thanks
Rob

TonyJollans
12-08-2007, 01:01 PM
Take a look at the code on the Word MVP page you looked at before - it shows you how to send a message with Outlook as well as the no-longer-available RoutingSlip method.

Robtyketto
12-08-2007, 01:05 PM
oOutlookApp As Outlook.Application ends up with error message user-defined type not defined.

Shame I will have to force the users to save first before sending the email too.

TonyJollans
12-08-2007, 01:15 PM
You need to set a Reference to the Outlook library.

In the VBE, select Tools > References from the Menu. Scroll down to find "Microsoft Outlook 12.0 Library", check the checkbox and press OK.

Robtyketto
12-08-2007, 01:54 PM
Life saver, checked for "Microsoft Outlook 12.0" and it's working.

Looking to see if I can get round the pre-saving the filename bit now.

Cheers much appreciated.

TonyJollans
12-08-2007, 02:33 PM
If I understand you correctly you have a document you want to e-mail as an attachment but you don't particularly want to have to save it. There's no way you can avoid saving it but you can save it to a temporary location and under a temporary name if you want and then delete it afterwards.