Code for Outlookworked now it doesn't ?!?! (1 Viewer)

jayhawker

New member
Local time
Yesterday, 19:24
Joined
May 25, 2015
Messages
6
Currently, I'm using MS Office Professional Plus 2010 and Windows 8.1. This code worked just fine then I started getting the 287 Error (Application Defined error). This is pretty frustrating any thoughts on how I can get it to work consistently????? Thank you in advance!!


PHP:
Function SendStuff_THISWORKED()


  Dim Email As String

  Dim objOutlook As Object
  Dim objEmail As Object
   
  

  Set objOutlook = CreateObject("Outlook.Application")
  Set objEmail = objOutlook.CreateItem(olMailItem)
   
  With objEmail
      .To = "xxxxxxx@xxxxxx.com"
      '.CC = strto
      '.BCC = strto
      .Subject = "Subject"
      .Body = "Body"
      .Send
  End With
   
  Set objOutlook = Nothing
  Set objEmail = Nothing

End Function
 

MarkK

bit cruncher
Local time
Yesterday, 19:24
Joined
Mar 17, 2004
Messages
8,187
Hi, welcome to the forum.

Which line causes the error?
 

jayhawker

New member
Local time
Yesterday, 19:24
Joined
May 25, 2015
Messages
6
Sorry.

. Send
 

TimW

Registered User.
Local time
Today, 03:24
Joined
Feb 6, 2007
Messages
90
Hi
It looks similar to code I have. I have used .display instead of .send....
However, if you put some error handling in so that the objects are set to nothing after an error, this may help... (or may not - I'm guessing)
HTH
T
 

vbaInet

AWF VIP
Local time
Today, 03:24
Joined
Jan 22, 2010
Messages
26,374
It might just be an Outlook setting that's preventing it from sending, so using .Display as TimW advised, should display the security alert (if it turns out to be the case).
 

jayhawker

New member
Local time
Yesterday, 19:24
Joined
May 25, 2015
Messages
6
It works now and all I did was:

1 Change .Send to .Display
2 Ran code (Outlook popped up with my email information)
3 Change .Display back to .Send
4 Ran code and email was sent no issues

WEIRDNESS!!!!!
 

Users who are viewing this thread

Top Bottom