create command button on word document to email me

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How can I create a button that people can press that will email me the
document they are working on?
 
There are issues relating to whether your users will allow macros from third
party documents to run and what e-mail application they may be using,
neither of which are under your control, but the following macro will mail
the document to you by using Outlook

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" 'The message subject
.Body = "See attached document" ' The message body text
.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

http://www.gmayor.com/installing_macro.htm


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

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
There are issues relating to whether your users will allow macros from third
party documents to run and what e-mail application they may be using,
neither of which are under your control, but the following macro will mail
the document to you by using Outlook

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" 'The message subject
.Body = "See attached document" ' The message body text
.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

http://www.gmayor.com/installing_macro.htm

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

My web sitewww.gmayor.com
Word MVP web sitehttp://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

Hello Graham,
I tried the code and it gave me the following error:
---------------------------
Microsoft Visual Basic
---------------------------
Compile error:

User-defined type not defined
---------------------------
And the following line was highlighted: oOutlookApp As
Outlook.Application

I use Thunderbird2, maybe this is the problem. If it is indeed, could
you modify your script so I can use it with TB2?
Thank you
 
Attila said:
Hello Graham,
I tried the code and it gave me the following error:
---------------------------
Microsoft Visual Basic
---------------------------
Compile error:

User-defined type not defined
---------------------------
And the following line was highlighted: oOutlookApp As
Outlook.Application

I use Thunderbird2, maybe this is the problem. If it is indeed, could
you modify your script so I can use it with TB2?
Thank you

In the vba editor, Tools > References - ensure that the Microsoft Outlook
object library is checked, which should make the Outlook commands available.
I don't know anything about Thunderbird, or what functions its object
library brings to the table.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
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

Back
Top