Email Word Document

T

Tim

Thank you in advance for your time.

I have a button at the bottom of my Word document that reads "SUBMIT" When I
click the button, is there anyway it could email itself to a particular
person?

It keeps prompting me to enter the email address. I'm trying to get around
it so I don't have to type the address in everytime I submit.

I do appreciate your time.

thanks,
tim

tim
 
G

Graham Mayor

The following will work - enter your address, subject and body text where
indicated.

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
ActiveDocument.Save
End If

Set oOutlookApp = GetObject(, "Outlook.Application")
If Err <> 0 Then
Set oOutlookApp = CreateObject("Outlook.Application")
bStarted = True
End If

Set oItem = oOutlookApp.CreateItem(olMailItem)

With oItem
.To = "(e-mail address removed)"
.Subject = "New subject"
.Body = "See attached document"
.Attachments.Add Source:=ActiveDocument.FullName, Type:=olByValue
.Send
End With

If bStarted Then
oOutlookApp.Quit
End If

Set oItem = Nothing
Set oOutlookApp = Nothing
End Sub


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


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

Tim

Hi Graham.

Thank you for your time. Your code is quit impressive.

I can not get it to work though.... on the first few lines of code is says
compile error.

Would it be becuase I'm in Word 2000?

Anyway, I do thank you. Your code was way good.

thanks again.
Tim
 
G

Graham Mayor

Open the vba editor and under tools > references, check the Outlook object
library.

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


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

Tim

Graham your gonna hate me for this...I got the Library checked like you
said...thank you.

It started to work until I found out I had Outlook Express. I'm sorry dam'it.

I tried to change a couple of things in the code myself to see if I could
avoid bothering you again.

If you feel like helping me anymore, well... that would be nice...I
appreciate all you have done already. Again I was very impressed with the
code. I could have never figured that out!!! How did you learn so much?

Thanks again Graham.

tim
 
R

Russ

Tim,
I'm, at this moment at home, using MacWord. But if I were you, I would try
substituting combinations of spelling of Outlook Express in the two places
where Graham had the exact phrase "Outlook.Application" and see if one way
of spelling it worked.
I.e.
"Outlook Express.Application"
"Outlook_Express.Application"
"OutlookExpress.Application"
 
T

Tim

Hi Russ...I first just want to thank you both again for your expertise.

Yes sir Russ, I did try that very exact thing you just mentioned. I didn't
want to be abother any more and that is why I tried a few different things.
I was my bad in the beginng for not knowing the right application. I'm have
to use both and just did't get it right.

Sorry and thank you all again.
 
G

Graham Mayor

I do not believe Outlook Express (unlike Outlook) is programmable from
within Word.

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
G

Graham Mayor

You are welcome :)

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


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

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