From the vba editor check tools > references > Microsoft Outlook object
library
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
tmirelle wrote:
> 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
>
> "Graham Mayor" wrote:
>
>> 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 = someone@somewhere.com '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
>>
>> My web site www.gmayor.com
>> Word MVP web site http://word.mvps.org
>> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
>>
>>
>> tmirelle wrote:
>>> Have added the function to a command button, but want to have it
>>> send to a specific email address
>>>
>>> Thanks!