word email macro

J

jatman

I'm back once again. i am working on a macro to send a word document as an
attachment. this is where i am so far:

file is created, saved as a docx file (Office 2007 on Vista), now i want to
email the file out to several recipients, in the array as follows:

Dim Recip As Variant
Recip = Array("(e-mail address removed)")
.SendMail

the file attached is correct and the subject line is the same as the file
name, so all of that is ok. at this point, the outlook dialog box opens up
and just sits there. it does not accept the recipient's email address. i
have tried the same portion of a macro from an excel file and i get an error
in word, but works fine in excel.

i have also checked http://word.mvps.org/FAQs/InterDev/SendMail.htm and
tried the routing slip method (smaller and clean macro,) but i got an error
5892 on that also.

any other suggestions to make this work?

jat
 
G

Graham Mayor

How about:

Sub SendDocumentAsAttachment()
Dim bStarted As Boolean
Dim Recip(2) As Variant
Dim oOutlookApp As Outlook.Application
Dim oItem As Outlook.MailItem

Recip(0) = "(e-mail address removed)"
Recip(1) = "(e-mail address removed)"
Recip(2) = "(e-mail address removed)"

On Error Resume Next
If Len(ActiveDocument.Path) = 0 Then 'Document has not been saved
ActiveDocument.Save 'so save it
End If
'see if Outlook is running and if so turn your attention there
Set oOutlookApp = GetObject(, "Outlook.Application")
If Err <> 0 Then 'Outlook isn't running
'So fire it up
Set oOutlookApp = CreateObject("Outlook.Application")
bStarted = True
End If
'Open a new e-mail message
For i = 0 To 2
Set oItem = oOutlookApp.CreateItem(olMailItem)
With oItem 'and add the detail to it
.To = Recip(i) 'send to this address
.Subject = "New subject" 'This is the message subject
.Body = "See attached document" ' This is the message body text
.Attachments.Add Source:=ActiveDocument.FullName, Type:=olByValue
.Send
End With
Next i
If bStarted Then 'If the macro started Outlook, stop it again.
oOutlookApp.Quit
End If
'Clean up
Set oItem = Nothing
Set oOutlookApp = Nothing
End Sub


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top