Jean,
I copied the following code because I wanted to do the same thing as Mike.
When I tested the button nothing happen so I went into the code and compiled
it and it doesn't like: oOutlookApp As Outlook.Application, it gave me the
error "Compile Error: User-defined type not defined".
Does it not like Outlook.Application? Any help would be MUCH appreciated.
Thanks!
"Jean-Guy Marcil" wrote:
> Bonjour,
>
> Dans son message, < Mike > écrivait :
> In this message, < Mike > wrote:
>
> | I have tried several times. Most of the time nothing
> | happens. But a couple of times I received an error which
> | highlighted the first line in the code (which is the
> | default code when I added the command button from the VB
> | toolbar. The code I am using is this....it is from the
> | website you provided. Knowing that all the users of this
> | form have Outlook, I chose this method for a test.
>
> The sub declaration line should be:
>
> Private Sub CommandButton1_Click()
>
> Insert the button in the document, access its code window, and between
>
> Private Sub CommandButton1_Click()
>
> End Sub
>
> paste the code you got from the web site, minus the "Sub" line and the "End
> Sub" line:
>
> '_______________________________________
> Dim bStarted As Boolean
> Dim oOutlookApp As Outlook.Application
> Dim oItem As Outlook.MailItem
>
> On Error Resume Next
>
> 'Get Outlook if it's running
> Set oOutlookApp = GetObject(, "Outlook.Application")
> If Err <> 0 Then
> 'Outlook wasn't running, start it from code
> Set oOutlookApp = CreateObject("Outlook.Application")
> bStarted = True
> End If
>
> 'Create a new mailitem
> Set oItem = oOutlookApp.CreateItem(olMailItem)
>
> With oItem
> 'Set the recipient for the new email
> .To = "recipient@mail.com"
> 'Set the recipient for a copy
> .CC = "recipient2@mail.com"
> 'Set the subject
> .Subject = "New subject"
> 'The content of the document is used as the body for
> the email
> .Body = ActiveDocument.Content
> .Send
> End With
>
> If bStarted Then
> 'If we started Outlook from code, then close it
> oOutlookApp.Quit
> End If
>
> 'Clean up
> Set oItem = Nothing
> Set oOutlookApp = Nothing
> '_______________________________________
>
> Try that and see how it goes. It should work.
> Don't forget to switch off the design mode before testing. It should work
> even if the form is protected.
Doug Robbins - 29 Jan 2005 01:10 GMT
You need to set a reference (in the Visual Basic editor Tools>References) to
the Outlook Object Library.

Signature
Please respond to the Newsgroup for the benefit of others who may be
interested. Questions sent directly to me will only be answered on a paid
consulting basis.
Hope this helps,
Doug Robbins - Word MVP
> Jean,
>
[quoted text clipped - 80 lines]
>> Don't forget to switch off the design mode before testing. It should work
>> even if the form is protected.