using a macro so send an email

G

Guest

Hi I have created an electronic form that i want filed out online. Once the
form is completed, I would like it to be emailed directly back to me. I have
tried to create a macro that will open up the email address bar and insert my
address into it then send but the macro wont run. When i get to the end of
the form the address bar just keeps opening up and waiting for someone to
type in and email address. Is there something i am missing here or is it
just not possible
 
G

Graham Mayor

the following will send the current document to "(e-mail address removed)" as
an attachment. Change that to your return e-mail address. Change the subject
and body text also. The document is sent straight to the Outbox of Outlook
and either sent immediately or when the user sends it according to the
user's Outlook settings.

Sub Send_As_Mail_Attachment()

' send the document as an attachment _
in an Outlook Email message
Dim bStarted As Boolean
Dim oOutlookApp As Outlook.Application
Dim oItem As Outlook.MailItem

On Error Resume Next
'Prompt the user to save the document
ActiveDocument.Save
'Get Outlook if it's running
Set oOutlookApp = GetObject(, "Outlook.Application")
'Outlook wasn't running, start it from code
If Err <> 0 Then
Set oOutlookApp = CreateObject("Outlook.Application")
bStarted = True
End If
'Create a new mailitem
Set oItem = oOutlookApp.CreateItem(olMailItem)

With oItem
.To = "(e-mail address removed)"
.Subject = "This is the subject"
.Attachments.Add Source:=ActiveDocument.FullName, _
Type:=olByValue, DisplayName:="Document as attachment"
.Body = "Returned Form"
.Send
End With

'Clean up
Set oItem = Nothing
Set oOutlookApp = Nothing
End Sub


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

My web site www.gmayor.com

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

Guest

Hi Graham.

This looked really cool and like something I could add to existing macros,
so I copied and pasted it into the VB editor and attempted to run it.
However, I get the following compile error: User-defined type not defined. In
the editor it has highlighted the statement Dim oOutlookApp As
Outlook.Application.

Any idea why it's returning this error? If it helps, my Outlook is currently
running.

Dan
 
J

Jay Freedman

To use things from the Outlook programming environment, you have to
set a reference to the Outlook library. Open your macro in the VBA
editor, go to Tools > References, and check the box next to "Microsoft
Outlook 11.0 Object Library".

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 
G

Graham Mayor

Oops - I was forgetting that the Outlook library was not installed by
default :(

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

My web site www.gmayor.com

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

Guest

That did the trick. Thanks much for the help.

Jay Freedman said:
To use things from the Outlook programming environment, you have to
set a reference to the Outlook library. Open your macro in the VBA
editor, go to Tools > References, and check the box next to "Microsoft
Outlook 11.0 Object Library".

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 

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