View Single Post
  #6   Report Post  
Posted to microsoft.public.word.docmanagement
Graham Mayor Graham Mayor is offline
external usenet poster
 
Posts: 19,312
Default using a macro so send an email

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

--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org


Jay Freedman wrote:
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".


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

"Graham Mayor" wrote:

the following will send the current document to
" 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 = "
.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
Word MVP web site http://word.mvps.org



Shazza wrote:
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