Recipients.add Run Time Error 287
Contents |
Forums Excel Questions Recipients.Add method causing Error 287 Results 1 to 10 of 10 Recipients.Add method causing Error 287This is a discussion on Recipients.Add method causing Error 287 within the Excel Questions forums, part of run time error 287 excel the Question Forums category; I am writing vba code to create Outlook tasks for error 287 application-defined or object-defined error various employees from an Excel spreadsheet. The spreadsheet contains a ... LinkBack LinkBack URL About LinkBacks Bookmark & Share Digg this excel vba runtime error 287 Thread!Add Thread to del.icio.usBookmark in TechnoratiTweet this thread Thread Tools Show Printable Version Display Linear Mode Switch to Hybrid Mode Switch to Threaded Mode May 20th, 2013,06:28 PM #1 Excel1user New Member Join Date May runtime error 287 excel 2013 Posts 6 Recipients.Add method causing Error 287 I am writing vba code to create Outlook tasks for various employees from an Excel spreadsheet. The spreadsheet contains a list of reports under review and who is assigned to review the task. I want the vba code to create an Outlook task for the individual assigned to review the report. I have found a number of websites with example code of how to
Runtime Error '287' Application-defined Or Object-defined Error
do this, but everytime I have tried to use the code I get the same error on the "Recipients.Add" line. The error is vba "Run-time error '287': Application-defined or object-defined error". Here is the code I'm using: (It is interesting to note that I have written code that successfully writes an e-mail, but that code uses the ".To" method, instead of the "Recipients.Add" method. Unfortunately the ".To" method is not available for Task Items.) Code: Option Explicit Sub createtask() Dim olApp As Outlook.Application, olNs As Outlook.Namespace, olTask As Outlook.TaskItem Set olApp = Outlook.Application Set olNs = olApp.GetNamespace("MAPI") olNs.Logon Set olTask = olApp.CreateItem(olTaskItem) olTask.Assign olTask.Subject = "Test" olTask.Body = "Testing macro" olTask.Recipients.Add ("myemail@myemail.com") olTask.Display End Sub Last edited by RoryA; May 21st, 2013 at 11:20 AM. Reason: add code tags Share Share this post on Digg Del.icio.us Technorati Twitter Reply With Quote May 20th, 2013,06:36 PM #2 Norie Board Regular Join Date Apr 2004 Location Stirling Posts 70,146 Re: Recipients.Add method causing Error 287 That code works fine for me. Is that the actual code that's causing an error? Share Share this post on Digg Del.icio.us Technorati Twitter If posting code please use code tags. Reply With Quote May 21st, 2013,11:08 AM #3 Excel1user New Member Join Date May 2013 Posts 6
from various sources.It works fine when Outlook is already running.If Outlook is not running I get Run Time Error 287 on the statement - Set myRecipients = myTempItem.RecipientsI tried adding some code to start up Outlook but it had no effect. Any ideas?!--c1-->CODEFunction OOBSNoReply()Dim myOlApp As New Outlook.ApplicationDim myNameSpace As Outlook.NamespaceDim myDistList As Outlook.DistListItemDim myTempItem As Outlook.MailItemDim myRecipients As Outlook.RecipientsDim OlApp As ObjectOn Error Resume NextSet OlApp = GetObject(, "Outlook.Application")On Error GoTo 0If Not OlApp Is http://www.mrexcel.com/forum/excel-questions/703891-recipients-add-method-causing-error-287-a.html Nothing Then'Outlook is open!Else'Outlook not openSet myOlApp = CreateObject("Outlook.Application")End IfSet myNameSpace = myOlApp.GetNamespace("MAPI")Set myDistList = myOlApp.CreateItem(olDistributionListItem)Set myTempItem = myOlApp.CreateItem(olMailItem)Set myRecipients = myTempItem.RecipientsmyDistList.DLName = "OOBS No Reply"myRecipients.Add myNameSpace.CurrentUser.NameDim dbs As dao.DatabaseDim rst As dao.RecordsetDim strSQL As StringDim XEmail As VariantstrSQL = "SELECT A.ATT_ID, C.FNM, C.SNM, C.PHONE, C.EMAIL " _ + "FROM [OOBS EVENT ATTENDEES] AS A, [OOBS MEMBERS] AS http://www.utteraccess.com/forum/lofiversion/index.php/t2008785.html C " _ + "WHERE A.ATT_ID = C.MBR_ID And A.EVT_ID = 23 And A.Reply = False And A.ATNDNG = False " _ + "And A.PLAYING = False ORDER BY 3, 2;"Set dbs = CurrentDb()Set rst = dbs.OpenRecordset(strSQL)If Not (rst.BOF And rst.EOF) ThenDo While Not rst.EOFXEmail = Nz(rst![EMAIL], 0)myRecipients.Add XEmailrst.MoveNextLoopEnd Ifrst.ClosemyRecipients.ResolveAllmyDistList.AddMembers myRecipientsmyDistList.SavemyDistList.Display' Clean up... MsgBox "All done...", vbMsgBoxSetForegroundmyNameSpace.LogoffSet myNameSpace = NothingSet myDistList = NothingSet myOlApp = NothingEnd Function Bob G Sep 5 2013, 06:02 AM always make a copy before making changes. urrent..CODEDim OlApp As ObjectOn Error Resume NextSet OlApp = GetObject(, "Outlook.Application")On Error GoTo 0If Not OlApp Is Nothing Then'Outlook is open!Else'Outlook not openSet myOlApp = CreateObject("Outlook.Application")End Iftry it this way..CODEOn Error Resume NextSet myOlApp = GetObject(, "Outlook.Application")On Error GoTo 0If Not myOlApp Is Nothing Then'Outlook is open!Else'Outlook not openSet myOlApp = CreateObject("Outlook.Application")End If johndr Sep 5 2013, 04:10 PM I did what you suggested but it made no difference. I got exactly the same error. As my code works if Outlook is already running then solving this is only of
Add-ins Database Connections Security Prompts Tips Outlook Forms Basics http://www.outlookcode.com/threads.aspx?forumid=2&messageid=29872 Form Controls Property Syntax Default Forms Import/Export Printing Languages VBA VBScript VB.NET & C# Samples Sue´s Book Samples Other VB/VBA http://www.dreamincode.net/forums/topic/349382-vba-outlook-resolving-name/ Samples Sample Outlook Forms Share Your Own Code More Outlook Resource Sites Microsoft Developer Network (MSDN) Outlook Developer Portal time error Office Developer Center MSDN Communities (discussion) FAQs and other general resources Slipstick Systems Outlook & Exchange Solutions Center DigidashLive.com Microsoft sending-mail-from-code FAQ forum 25-Oct-2016 23:40 Looking for help with Outlook programming projects — VSTO, add-ins, VBA, custom Outlook forms, etc.? time error 287 You′ve come to the right place! NEW! >> Subscribe to this site via RSS. For more RSS options, see the complete list of feeds on our main news page. Page [ ] Basic Outlook Outlook Form Design Outlook Expert Techniques Outlook and .NET Code Essentials 10 per page 15 per page 25 per page 50 per page Printer Friendly Version Topic Page [ ] Basic Outlook Outlook Form Design Outlook Expert Techniques Outlook and .NET Code Essentials 10 per page 15 per page 25 per page 50 per page home | get Sue's code | forums | share your own code | © 2013 Add-in Express Ltd. All rights reserved. About OutlookCode.com
New Topic/Question Reply 14 Replies - 1912 Views - Last Post: 27 June 2014 - 03:04 PM Rate Topic: #1 xtreampb D.I.C Regular Reputation: 14 Posts: 343 Joined: 20-June 07 VBA outlook resolving name Posted 27 June 2014 - 06:04 AM Hello all, I'm using VBA. I'm trying to take a string that represents a name and resolve it to an exchange user so that i can extract information such as firs name last name e-mail phone number and a few other things. this is what I had in access, and yes I added the reference to outlook 14 object type. I'm using MS 2010 Private Sub getUser(First As String, Last As String, Middle As String) Dim oApp As Outlook.Application Dim oTI As Outlook.TaskItem Dim oRec As Outlook.Recipient Dim cust As ExchangeUser Set oApp = CreateObject("Outlook.Application") Set oTI = oApp.CreateItem(olTaskItem) oTI = oTI.Assign Dim Usr As String Usr = Last & ", " & First & " " & Middle Set oRec = oTI.Recipients.Add("1053347491A")'errors here oRec.Resolve Set cust = oRec.AddressEntry.GetExchangeUser Me.txtFirst.Value = cust.FirstName Me.txtLast.Value = cust.LastName Me.txtNum.Value = cust.BusinessTelephoneNumber Me.txtMail.Value = cust.PrimarySmtpAddress end sub the error thrown is "run-time error '287': Application-defined or object-defined error" which is very vague and generic. Since the error is thown when dealing with outlook i decided to run this in outlook. I then set up the following code in outlook Private Sub getUser() Dim oApp As Outlook.Application Dim oTI As Outlook.TaskItem Dim oRec As Outlook.Recipient Dim cust As ExchangeUser Set oApp = New Outlook.Application Set oTI = oApp.CreateItem(olTaskItem) oTI = oTI.Assign 'Dim Usr As String 'Usr = Last & ", " & First & " " & Middle Set oRec = oTI.Recipients.Add("1053347491A")'error thrown here oRec.Resolve Set cust = oRec.AddressEntry.GetExchangeUser MsgBox cust.PrimarySmtpAddress End Sub Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean) Call getUser End Sub the same error is thrown on the same line with the same error. However, this time when I click on help I am directed to the olkLable Object->properties page. on this page the olklabel.MouseIcon property is w