Add recipient email to 'ActiveDocument.SendMail'

T

tmirelle

Have added the function to a command button, but want to have it send to a
specific email address

Thanks!
 
G

Graham Mayor

If you are using Outlook you can use something like the following

Sub SendDocumentAsAttachment()
Dim bStarted As Boolean
Dim oOutlookApp As Outlook.Application
Dim oItem As Outlook.MailItem
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
Set oItem = oOutlookApp.CreateItem(olMailItem)
With oItem 'and add the detail to it
.To = (e-mail address removed) '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
'**********************************
'If you want to view the message before it goes
'change the line above from .Send to .Display
'Otherwise the message is sent straight to the Outbox
'and if you have Outlook set to send mail immediately,
'it will simply be Sent
'with no obvious sign that Outlook has operated.
'Apart from the copy in the Outlook Sent folder
'**********************************
End With
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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
T

tmirelle

Thnx

Macro stops at this line indicating error

Dim oOutlookApp As Outlook.Application

" Compile error: User defined type item not defined"

I have this attached to a submit button as an on click function
 
G

Graham Mayor

From the vba editor check tools > references > Microsoft Outlook object
library

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
T

tmirelle

Now it does nothing at all...any other suggestions?

can I email you the document?
 
G

Graham Mayor

Send it to the link on mu web site

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
C

Chris Dolphin

I'd like to send the document AS the email - instead of attaching
it.......any ideas ?
Ultimately I'd like a drop down in the document with a list of departments -
when the user selects a department - it refers to a look-up in the code and
selects the appropriate email address (only 8 or so email addresses).
Out anti-spam is also quarantining the sent email.....as it has a base64.txt
attachment ?
Chris
 
J

JBK617

Resurrecting an old thread here butI have a questions as to where to insert
the code;

Would I insert this code in a module, or in with this:

Private Sub CommandButton1_Click()

End Sub

Thanks,
Rick
 
D

Doug Robbins - Word MVP

The code is designed to be inserted into a module.

See the article "What do I do with macros sent to me by other newsgroup
readers to help me out?†at:

http://www.word.mvps.org/FAQs/MacrosVBA/CreateAMacro.htm


--
Hope this helps,

Doug Robbins - Word MVP

Please reply only to the newsgroups unless you wish to obtain my services on
a paid professional basis.
 

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