Creating Email to send in OUTLOOK m?

liamfitz

Registered User.
Local time
Today, 20:44
Joined
May 17, 2012
Messages
240
Here's my code, to 'auto-generate' an e-mail, at the triggering of an event ....
Code:
Public Function Email_Via_Outlook(varAddress, varSubject, varBody)
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
On Error GoTo errorHandler
' Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")
' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
With objOutlookMsg
    ' Add the To recipient(s) to the message.
    Set objOutlookRecip = .Recipients.Add(varAddress)
    objOutlookRecip.Type = olTo
    .Subject = varSubject
    .Body = varBody
    .Send
End With
errorHandler:
errNameFrom = "Email_Via_Outlook"
MsgBox "Error occured at " & errNameFrom & ": " & Err.Number & "; " & Err.Description
End Function

I get the following error message - " Error occurred at EMail_Via_Outlook: 287; Application defined or object defined error ( see MsgBox code )
 
It is not wise to have error handling enabled during development and then try to debug, because you do not know which line caused the error.

Comment out the On Error and determine which line errored.

Prior to that, go to the code window, Debug->Compile and see if it comes up with something.
 
Did you enable the Microsoft Outlook Reference?

If not, go under Tools/References and select Microsoft Outlook 12.0 Object Library.
 

Users who are viewing this thread

Back
Top Bottom