Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / January 2005

Tip: Looking for answers? Try searching our database.

Email Command Button - Jean-Guy Marcil

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
SMac - 28 Jan 2005 13:37 GMT
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.

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.